<!DOCTYPE html>
<html lang="en-US" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>基础知识 | VitePress</title>
    <meta name="description" content="A VitePress site">
    <link rel="preload stylesheet" href="/notebook/assets/style.3dbfd0c2.css" as="style">
    
    <script type="module" src="/notebook/assets/app.8aaa4cbe.js"></script>
    <link rel="preload" href="/notebook/assets/inter-roman-latin.2ed14f66.woff2" as="font" type="font/woff2" crossorigin="">
    <link rel="modulepreload" href="/notebook/assets/chunks/framework.1336c4e5.js">
    <link rel="modulepreload" href="/notebook/assets/chunks/theme.20cddc0c.js">
    <link rel="modulepreload" href="/notebook/assets/云原生_Docker.md.983c7ba7.lean.js">
    <script id="check-dark-light">(()=>{const e=localStorage.getItem("vitepress-theme-appearance")||"",a=window.matchMedia("(prefers-color-scheme: dark)").matches;(!e||e==="auto"?a:e==="dark")&&document.documentElement.classList.add("dark")})();</script>
  </head>
  <body>
    <div id="app"><div class="Layout" data-v-255ec12d><!--[--><!--]--><!--[--><span tabindex="-1" data-v-ae3e3f51></span><a href="#VPContent" class="VPSkipLink visually-hidden" data-v-ae3e3f51> Skip to content </a><!--]--><!----><header class="VPNav" data-v-255ec12d data-v-7e5bc4a5><div class="VPNavBar has-sidebar" data-v-7e5bc4a5 data-v-0937f67c><div class="container" data-v-0937f67c><div class="title" data-v-0937f67c><div class="VPNavBarTitle has-sidebar" data-v-0937f67c data-v-86d1bed8><a class="title" href="/notebook/" data-v-86d1bed8><!--[--><!--]--><!--[--><img class="VPImage logo" src="/notebook/Vue.png" alt data-v-8426fc1a><!--]--><!--[-->任硕的文档<!--]--><!--[--><!--]--></a></div></div><div class="content" data-v-0937f67c><div class="curtain" data-v-0937f67c></div><div class="content-body" data-v-0937f67c><!--[--><!--]--><div class="VPNavBarSearch search" style="--vp-meta-key:&#39;Meta&#39;;" data-v-0937f67c><!--[--><!----><div id="docsearch"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search"><span class="DocSearch-Button-Container"><svg class="DocSearch-Search-Icon" width="20" height="20" viewBox="0 0 20 20" aria-label="search icon"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"><kbd class="DocSearch-Button-Key"></kbd><kbd class="DocSearch-Button-Key">K</kbd></span></button></div><!--]--></div><nav aria-labelledby="main-nav-aria-label" class="VPNavBarMenu menu" data-v-0937f67c data-v-7f418b0f><span id="main-nav-aria-label" class="visually-hidden" data-v-7f418b0f>Main Navigation</span><!--[--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-7f418b0f data-v-a7b5672a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-a7b5672a><span class="text" data-v-a7b5672a><!----><span data-v-a7b5672a>Java学前端</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-a7b5672a><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-a7b5672a><div class="VPMenu" data-v-a7b5672a data-v-e7ea1737><div class="items" data-v-e7ea1737><!--[--><!--[--><div class="VPMenuGroup" data-v-e7ea1737 data-v-69e747b5><!----><!--[--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/Java%E5%AD%A6%E5%89%8D%E7%AB%AF/HTML+JS.html" data-v-2f2cfafc><!--[-->HTML+JS<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/Java%E5%AD%A6%E5%89%8D%E7%AB%AF/CSS.html" data-v-2f2cfafc><!--[-->CSS<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/Java%E5%AD%A6%E5%89%8D%E7%AB%AF/Vue2+%E7%BB%84%E4%BB%B6.html" data-v-2f2cfafc><!--[-->Vue2+组件<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/Java%E5%AD%A6%E5%89%8D%E7%AB%AF/Vue3+%E7%BB%84%E4%BB%B6.html" data-v-2f2cfafc><!--[-->Vue3+组件<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/Java%E5%AD%A6%E5%89%8D%E7%AB%AF/React.html" data-v-2f2cfafc><!--[-->React<!--]--></a></div><!--]--><!--]--></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-7f418b0f data-v-a7b5672a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-a7b5672a><span class="text" data-v-a7b5672a><!----><span data-v-a7b5672a>软件测试</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-a7b5672a><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-a7b5672a><div class="VPMenu" data-v-a7b5672a data-v-e7ea1737><div class="items" data-v-e7ea1737><!--[--><!--[--><div class="VPMenuGroup" data-v-e7ea1737 data-v-69e747b5><!----><!--[--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E6%B5%8B%E8%AF%95%E5%9F%BA%E7%A1%80.html" data-v-2f2cfafc><!--[-->测试基础<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95/%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95.html" data-v-2f2cfafc><!--[-->压力测试<!--]--></a></div><!--]--><!--]--></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-7f418b0f data-v-a7b5672a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-a7b5672a><span class="text" data-v-a7b5672a><!----><span data-v-a7b5672a>多线程</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-a7b5672a><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-a7b5672a><div class="VPMenu" data-v-a7b5672a data-v-e7ea1737><div class="items" data-v-e7ea1737><!--[--><!--[--><div class="VPMenuGroup" data-v-e7ea1737 data-v-69e747b5><!----><!--[--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E5%B9%B6%E5%8F%91%20&amp;%20%E5%A4%9A%E7%BA%BF%E7%A8%8B/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-2f2cfafc><!--[-->基础篇<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E5%B9%B6%E5%8F%91%20&amp;%20%E5%A4%9A%E7%BA%BF%E7%A8%8B/%E5%B9%B6%E5%8F%91%E5%AE%8C%E5%96%84.html" data-v-2f2cfafc><!--[-->进阶篇<!--]--></a></div><!--]--><!--]--></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-7f418b0f data-v-a7b5672a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-a7b5672a><span class="text" data-v-a7b5672a><!----><span data-v-a7b5672a>开发工具</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-a7b5672a><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-a7b5672a><div class="VPMenu" data-v-a7b5672a data-v-e7ea1737><div class="items" data-v-e7ea1737><!--[--><!--[--><div class="VPMenuGroup" data-v-e7ea1737 data-v-69e747b5><!----><!--[--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/IDEA/Chrome.html" data-v-2f2cfafc><!--[-->Chrome<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/IDEA/IDEA%E5%9F%BA%E7%A1%80.html" data-v-2f2cfafc><!--[-->IDEA基础<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/IDEA/IDEA%E6%8F%92%E4%BB%B6.html" data-v-2f2cfafc><!--[-->IDEA插件<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/IDEA/VS%20Code.html" data-v-2f2cfafc><!--[-->VS Code<!--]--></a></div><!--]--><!--]--></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--[--><div class="VPFlyout VPNavBarMenuGroup" data-v-7f418b0f data-v-a7b5672a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" data-v-a7b5672a><span class="text" data-v-a7b5672a><!----><span data-v-a7b5672a>消息中间件</span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="text-icon" data-v-a7b5672a><path d="M12,16c-0.3,0-0.5-0.1-0.7-0.3l-6-6c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l5.3,5.3l5.3-5.3c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-6,6C12.5,15.9,12.3,16,12,16z"></path></svg></span></button><div class="menu" data-v-a7b5672a><div class="VPMenu" data-v-a7b5672a data-v-e7ea1737><div class="items" data-v-e7ea1737><!--[--><!--[--><div class="VPMenuGroup" data-v-e7ea1737 data-v-69e747b5><!----><!--[--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E4%BB%B6/RabbitMQ.html" data-v-2f2cfafc><!--[-->RabbitMQ<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E4%BB%B6/RocketMQ.html" data-v-2f2cfafc><!--[-->RocketMQ<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E4%BB%B6/Kafka.html" data-v-2f2cfafc><!--[-->Kafka<!--]--></a></div><!--]--><!--[--><div class="VPMenuLink" data-v-69e747b5 data-v-2f2cfafc><a class="VPLink link" href="/notebook/%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E4%BB%B6/Canal.html" data-v-2f2cfafc><!--[-->Canal<!--]--></a></div><!--]--><!--]--></div><!--]--><!--]--></div><!--[--><!--]--></div></div></div><!--]--><!--]--></nav><!----><div class="VPNavBarAppearance appearance" data-v-0937f67c data-v-f6a63727><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="toggle dark mode" aria-checked="false" data-v-f6a63727 data-v-82b282f1 data-v-f3c41672><span class="check" data-v-f3c41672><span class="icon" data-v-f3c41672><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-82b282f1><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-82b282f1><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div><div class="VPSocialLinks VPNavBarSocialLinks social-links" data-v-0937f67c data-v-0394ad82 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/renshuo123/renshuo123.github.io" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-f80f8133><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg></a><a class="VPSocialLink no-icon" href="#" aria-label="twitter" target="_blank" rel="noopener" data-v-7bc22406 data-v-f80f8133><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Twitter</title><path d="M23.953 4.57a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.69 8.095 4.067 6.13 1.64 3.162a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.06a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.936 4.936 0 004.604 3.417 9.867 9.867 0 01-6.102 2.105c-.39 0-.779-.023-1.17-.067a13.995 13.995 0 007.557 2.209c9.053 0 13.998-7.496 13.998-13.985 0-.21 0-.42-.015-.63A9.935 9.935 0 0024 4.59z"/></svg></a><a class="VPSocialLink no-icon" href="https://github.com/" aria-label target="_blank" rel="noopener" data-v-7bc22406 data-v-f80f8133><svg t="1676028692954" class="icon" ...</path></svg></a><!--]--></div><div class="VPFlyout VPNavBarExtra extra" data-v-0937f67c data-v-40855f84 data-v-a7b5672a><button type="button" class="button" aria-haspopup="true" aria-expanded="false" aria-label="extra navigation" data-v-a7b5672a><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="icon" data-v-a7b5672a><circle cx="12" cy="12" r="2"></circle><circle cx="19" cy="12" r="2"></circle><circle cx="5" cy="12" r="2"></circle></svg></button><div class="menu" data-v-a7b5672a><div class="VPMenu" data-v-a7b5672a data-v-e7ea1737><!----><!--[--><!--[--><!----><div class="group" data-v-40855f84><div class="item appearance" data-v-40855f84><p class="label" data-v-40855f84>Appearance</p><div class="appearance-action" data-v-40855f84><button class="VPSwitch VPSwitchAppearance" type="button" role="switch" title="toggle dark mode" aria-checked="false" data-v-40855f84 data-v-82b282f1 data-v-f3c41672><span class="check" data-v-f3c41672><span class="icon" data-v-f3c41672><!--[--><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="sun" data-v-82b282f1><path d="M12,18c-3.3,0-6-2.7-6-6s2.7-6,6-6s6,2.7,6,6S15.3,18,12,18zM12,8c-2.2,0-4,1.8-4,4c0,2.2,1.8,4,4,4c2.2,0,4-1.8,4-4C16,9.8,14.2,8,12,8z"></path><path d="M12,4c-0.6,0-1-0.4-1-1V1c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,3.6,12.6,4,12,4z"></path><path d="M12,24c-0.6,0-1-0.4-1-1v-2c0-0.6,0.4-1,1-1s1,0.4,1,1v2C13,23.6,12.6,24,12,24z"></path><path d="M5.6,6.6c-0.3,0-0.5-0.1-0.7-0.3L3.5,4.9c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C6.2,6.5,5.9,6.6,5.6,6.6z"></path><path d="M19.8,20.8c-0.3,0-0.5-0.1-0.7-0.3l-1.4-1.4c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l1.4,1.4c0.4,0.4,0.4,1,0,1.4C20.3,20.7,20,20.8,19.8,20.8z"></path><path d="M3,13H1c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S3.6,13,3,13z"></path><path d="M23,13h-2c-0.6,0-1-0.4-1-1s0.4-1,1-1h2c0.6,0,1,0.4,1,1S23.6,13,23,13z"></path><path d="M4.2,20.8c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C4.7,20.7,4.5,20.8,4.2,20.8z"></path><path d="M18.4,6.6c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l1.4-1.4c0.4-0.4,1-0.4,1.4,0s0.4,1,0,1.4l-1.4,1.4C18.9,6.5,18.6,6.6,18.4,6.6z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="moon" data-v-82b282f1><path d="M12.1,22c-0.3,0-0.6,0-0.9,0c-5.5-0.5-9.5-5.4-9-10.9c0.4-4.8,4.2-8.6,9-9c0.4,0,0.8,0.2,1,0.5c0.2,0.3,0.2,0.8-0.1,1.1c-2,2.7-1.4,6.4,1.3,8.4c2.1,1.6,5,1.6,7.1,0c0.3-0.2,0.7-0.3,1.1-0.1c0.3,0.2,0.5,0.6,0.5,1c-0.2,2.7-1.5,5.1-3.6,6.8C16.6,21.2,14.4,22,12.1,22zM9.3,4.4c-2.9,1-5,3.6-5.2,6.8c-0.4,4.4,2.8,8.3,7.2,8.7c2.1,0.2,4.2-0.4,5.8-1.8c1.1-0.9,1.9-2.1,2.4-3.4c-2.5,0.9-5.3,0.5-7.5-1.1C9.2,11.4,8.1,7.7,9.3,4.4z"></path></svg><!--]--></span></span></button></div></div></div><div class="group" data-v-40855f84><div class="item social-links" data-v-40855f84><div class="VPSocialLinks social-links-list" data-v-40855f84 data-v-7bc22406><!--[--><a class="VPSocialLink no-icon" href="https://github.com/renshuo123/renshuo123.github.io" aria-label="github" target="_blank" rel="noopener" data-v-7bc22406 data-v-f80f8133><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>GitHub</title><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg></a><a class="VPSocialLink no-icon" href="#" aria-label="twitter" target="_blank" rel="noopener" data-v-7bc22406 data-v-f80f8133><svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Twitter</title><path d="M23.953 4.57a10 10 0 01-2.825.775 4.958 4.958 0 002.163-2.723c-.951.555-2.005.959-3.127 1.184a4.92 4.92 0 00-8.384 4.482C7.69 8.095 4.067 6.13 1.64 3.162a4.822 4.822 0 00-.666 2.475c0 1.71.87 3.213 2.188 4.096a4.904 4.904 0 01-2.228-.616v.06a4.923 4.923 0 003.946 4.827 4.996 4.996 0 01-2.212.085 4.936 4.936 0 004.604 3.417 9.867 9.867 0 01-6.102 2.105c-.39 0-.779-.023-1.17-.067a13.995 13.995 0 007.557 2.209c9.053 0 13.998-7.496 13.998-13.985 0-.21 0-.42-.015-.63A9.935 9.935 0 0024 4.59z"/></svg></a><a class="VPSocialLink no-icon" href="https://github.com/" aria-label target="_blank" rel="noopener" data-v-7bc22406 data-v-f80f8133><svg t="1676028692954" class="icon" ...</path></svg></a><!--]--></div></div></div><!--]--><!--]--></div></div></div><!--[--><!--]--><button type="button" class="VPNavBarHamburger hamburger" aria-label="mobile navigation" aria-expanded="false" aria-controls="VPNavScreen" data-v-0937f67c data-v-e5dd9c1c><span class="container" data-v-e5dd9c1c><span class="top" data-v-e5dd9c1c></span><span class="middle" data-v-e5dd9c1c></span><span class="bottom" data-v-e5dd9c1c></span></span></button></div></div></div></div><!----></header><div class="VPLocalNav reached-top" data-v-255ec12d data-v-5cfd5582><button class="menu" aria-expanded="false" aria-controls="VPSidebarNav" data-v-5cfd5582><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="menu-icon" data-v-5cfd5582><path d="M17,11H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,11,17,11z"></path><path d="M21,7H3C2.4,7,2,6.6,2,6s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,7,21,7z"></path><path d="M21,15H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h18c0.6,0,1,0.4,1,1S21.6,15,21,15z"></path><path d="M17,19H3c-0.6,0-1-0.4-1-1s0.4-1,1-1h14c0.6,0,1,0.4,1,1S17.6,19,17,19z"></path></svg><span class="menu-text" data-v-5cfd5582>Menu</span></button><div class="VPLocalNavOutlineDropdown" style="--vp-vh:0px;" data-v-5cfd5582 data-v-18201f51><button data-v-18201f51>Return to top</button><!----></div></div><aside class="VPSidebar" data-v-255ec12d data-v-845b8fc6><div class="curtain" data-v-845b8fc6></div><nav class="nav" id="VPSidebarNav" aria-labelledby="sidebar-aria-label" tabindex="-1" data-v-845b8fc6><span class="visually-hidden" id="sidebar-aria-label" data-v-845b8fc6> Sidebar Navigation </span><!--[--><!--]--><!--[--><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>Java</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Java/Java%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Java基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Java/Java%E6%96%B0%E7%89%B9%E6%80%A7.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Java新特性</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Java/Java%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Java进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Java/Java%E9%9B%86%E5%90%88.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Java集合</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Java/Java%E9%AB%98%E7%BA%A7.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Java高级</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>Linux</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Linux/Linux%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Linux基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Linux/Linux%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Linux新特性</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Linux/Shell.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Shell脚本</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Linux/%E5%AE%9E%E7%94%A8%E8%84%9A%E6%9C%AC.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>实用脚本</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Linux/%E8%BD%AF%E4%BB%B6%E9%83%A8%E7%BD%B2.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>软件部署</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>Nginx</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Nginx/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>基础篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Nginx/%E8%BF%9B%E9%98%B6%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>进阶篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Nginx/%E5%AE%9E%E6%88%98%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>实战篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Nginx/%E9%9D%A2%E8%AF%95%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>面试篇</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>SSM</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/SSM/Maven.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Maven</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/SSM/Spring.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Spring</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/SSM/SpringMVC.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>SpringMVC</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/SSM/SpringBatch.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>SpringBatch</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>SpringBoot</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/3%E3%80%81SpringBoot/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>基础篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/3%E3%80%81SpringBoot/%E5%BA%94%E7%94%A8%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>应用篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/3%E3%80%81SpringBoot/%E6%96%B0%E7%89%B9%E6%80%A7.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>新特性</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/3%E3%80%81SpringBoot/%E8%BF%90%E7%BB%B4&amp;%E5%8E%9F%E7%90%86.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>运维&原理</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>SpringCloud</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/4%E3%80%81%E5%BE%AE%E6%9C%8D%E5%8A%A1/%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>SpringCloud</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/4%E3%80%81%E5%BE%AE%E6%9C%8D%E5%8A%A1/%E5%BF%85%E5%A4%87/Sentinel.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Sentinel</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>SpringSecurity</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/4%E3%80%81%E5%BE%AE%E6%9C%8D%E5%8A%A1/SpringSecurity/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>SpringSecurity基础篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/4%E3%80%81%E5%BE%AE%E6%9C%8D%E5%8A%A1/SpringSecurity/%E8%BF%9B%E9%98%B6%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>SpringSecurity进阶篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/4%E3%80%81%E5%BE%AE%E6%9C%8D%E5%8A%A1/SpringSecurity/%E9%AB%98%E7%BA%A7%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>SpringSecurity高级篇</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>Mybatis & MybatisPlus</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Mybatis&amp;MybatisPlus/Mybatis.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Mybatis</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Mybatis&amp;MybatisPlus/MybatisPlus.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MybatisPlus</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/Mybatis&amp;MybatisPlus/JPA.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>JPA</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>Git & ChatGPT</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/5%E3%80%81%E8%BF%90%E7%BB%B4/Git.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Git</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/5%E3%80%81%E8%BF%90%E7%BB%B4/Github.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Github</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/5%E3%80%81%E8%BF%90%E7%BB%B4/ChatGPT.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>ChatGPT</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/5%E3%80%81%E8%BF%90%E7%BB%B4/Jenkins.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Jenkins</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/5%E3%80%81%E8%BF%90%E7%BB%B4/Netty.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Netty</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>数据库</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>MySQL</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/MySQL%E6%A0%B8%E5%BF%83/%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MySQL基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/MySQL%E6%A0%B8%E5%BF%83/%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MySQL进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/MySQL%E6%A0%B8%E5%BF%83/%E4%BC%98%E5%8C%96.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MySQL优化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/MySQL%E6%A0%B8%E5%BF%83/%E8%AE%BE%E8%AE%A1.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MySQL设计</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/MySQL%E6%A0%B8%E5%BF%83/%E8%BF%90%E7%BB%B4.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MySQL运维</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MySQL/%E5%88%86%E5%BA%93%E5%88%86%E8%A1%A8.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>分库分表</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>Redis</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/Redis/Redis%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Redis基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/Redis/Redis%E4%BC%98%E5%8C%96.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Redis优化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/Redis/Redis%E5%8E%9F%E7%90%86.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Redis原理</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/Redis/Redis%E9%AB%98%E7%BA%A7.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Redis高级</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/Redis/Redis%E5%AE%9E%E6%88%98.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Redis实战</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/Redis/%E6%9C%AC%E5%9C%B0%E7%BC%93%E5%AD%98.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>本地缓存</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>MongoDB</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MongoDB/%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MongoDB基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/MongoDB/%E6%95%B4%E5%90%88.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>MongoDB进阶</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>ElasticSearch</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/ElasticSearch/1%E3%80%81ES%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>ES基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/ElasticSearch/3%E3%80%81ES%E9%AB%98%E7%BA%A7.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>ES高级</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/influxdb.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>InfluxDB</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/2%E3%80%81%E6%95%B0%E6%8D%AE%E5%BA%93/Neo4j.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Neo4j</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>高并发 & 秒杀 & 分布式</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E4%B8%89%E9%AB%98/%E5%88%86%E5%B8%83%E5%BC%8F.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>分布式理论</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/4%E3%80%81%E5%BE%AE%E6%9C%8D%E5%8A%A1/%E5%BF%85%E5%A4%87/%E5%88%86%E5%B8%83%E5%BC%8F%E9%94%81.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>分布式锁</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E4%B8%89%E9%AB%98/%E7%A7%92%E6%9D%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>秒杀</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E4%B8%89%E9%AB%98/%E9%AB%98%E5%8F%AF%E7%94%A8.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>高可用</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E4%B8%89%E9%AB%98/%E9%AB%98%E5%B9%B6%E5%8F%91.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>高并发</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible has-active" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>云原生</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E4%BA%91%E5%8E%9F%E7%94%9F/Docker.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Docker</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E4%BA%91%E5%8E%9F%E7%94%9F/K8S.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>K8S</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>可视化 & 监控</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E5%8F%AF%E8%A7%86%E5%8C%96%20&amp;%20%E7%9B%91%E6%8E%A7/%E7%9B%91%E6%8E%A7%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>监控基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E5%8F%AF%E8%A7%86%E5%8C%96%20&amp;%20%E7%9B%91%E6%8E%A7/%E7%9B%91%E6%8E%A7%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>监控进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E5%8F%AF%E8%A7%86%E5%8C%96%20&amp;%20%E7%9B%91%E6%8E%A7/%E5%8F%AF%E8%A7%86%E5%8C%96%E5%A4%A7%E5%B1%8F.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>可视化大屏</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E5%8F%AF%E8%A7%86%E5%8C%96%20&amp;%20%E7%9B%91%E6%8E%A7/Zabbix.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Zabbix</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>学前端</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>HTML+CSS</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/1%E3%80%81HTML+CSS/HTML%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>HTML基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/1%E3%80%81HTML+CSS/CSS%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>CSS基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/1%E3%80%81HTML+CSS/%E7%BD%91%E9%A1%B5%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>网页进阶</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>JS+TS</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/2%E3%80%81JS+TS/JS%20%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>JS基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/2%E3%80%81JS+TS/JS%20%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>JS进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/2%E3%80%81JS+TS/ES6%20%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>ES6基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/2%E3%80%81JS+TS/ES6%20%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>ES6进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/2%E3%80%81JS+TS/TypeScript.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>TS基础</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>NodeJS</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/4%E3%80%81Node/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Node基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/4%E3%80%81Node/%E8%BF%9B%E9%98%B6%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Node进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/4%E3%80%81Node/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>项目实战</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>Vue</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/3%E3%80%81Vue/Vue3/Vue3%E8%BF%9B%E9%98%B6.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Vue3进阶</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/3%E3%80%81Vue/Vue3/Vue3%E9%AB%98%E7%BA%A7.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Vue3高级</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/3%E3%80%81Vue/Vue3/Vue3%E6%96%B0%E8%AF%AD%E6%B3%95.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>Vue3新语法</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/3%E3%80%81Vue/Vue2/Vue2%E9%A1%B9%E7%9B%AE.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>项目实战</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>小程序</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/5%E3%80%81%E5%B0%8F%E7%A8%8B%E5%BA%8F/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>小程序基础</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/5%E3%80%81%E5%B0%8F%E7%A8%8B%E5%BA%8F/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E4%BC%98%E5%8C%96.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>小程序优化</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/5%E3%80%81%E5%B0%8F%E7%A8%8B%E5%BA%8F/uniapp.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>uniapp</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/1%E3%80%81%E5%AD%A6%E5%89%8D%E7%AB%AF/5%E3%80%81%E5%B0%8F%E7%A8%8B%E5%BA%8F/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%A1%B9%E7%9B%AE.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>项目实战</p><!--]--></a><!----></div><!----></div><!--]--></div></section><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>计算机基础</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>数据结构</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>操作系统</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>设计模式</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>计算机网络</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/UML.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>UML</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E8%AE%A1%E7%AE%97%E6%9C%BA%E5%9F%BA%E7%A1%80/%E7%AE%97%E6%B3%95/LeetCode.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>LeetCode</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0 collapsible collapsed" data-v-845b8fc6 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h2 class="text" data-v-9b797284>项目实战</h2><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>云尚办公</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E4%BA%91%E5%B0%9A%E5%8A%9E%E5%85%AC/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>基础篇</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>小兔鲜</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E5%B0%8F%E5%85%94%E9%B2%9C/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>基础篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E5%B0%8F%E5%85%94%E9%B2%9C/%E8%BF%9B%E9%98%B6%E7%AF%871.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>进阶篇1</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E5%B0%8F%E5%85%94%E9%B2%9C/%E8%BF%9B%E9%98%B6%E7%AF%872.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>进阶篇2</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>地图</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>基础篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE/%E8%BF%9B%E9%98%B6%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>进阶篇</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>苍穹外卖</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E8%8B%8D%E7%A9%B9%E5%A4%96%E5%8D%96/%E8%BF%9B%E9%98%B6%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>进阶篇</p><!--]--></a><!----></div><!----></div><!--]--></div></section><section class="VPSidebarItem level-1 collapsible collapsed" data-v-9b797284 data-v-9b797284><div class="item" role="button" tabindex="0" data-v-9b797284><div class="indicator" data-v-9b797284></div><h3 class="text" data-v-9b797284>黑马头条</h3><div class="caret" role="button" aria-label="toggle section" tabindex="0" data-v-9b797284><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" viewbox="0 0 24 24" class="caret-icon" data-v-9b797284><path d="M9,19c-0.3,0-0.5-0.1-0.7-0.3c-0.4-0.4-0.4-1,0-1.4l5.3-5.3L8.3,6.7c-0.4-0.4-0.4-1,0-1.4s1-0.4,1.4,0l6,6c0.4,0.4,0.4,1,0,1.4l-6,6C9.5,18.9,9.3,19,9,19z"></path></svg></div></div><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E9%BB%91%E9%A9%AC%E5%A4%B4%E6%9D%A1/%E5%9F%BA%E7%A1%80%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>基础篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E9%BB%91%E9%A9%AC%E5%A4%B4%E6%9D%A1/%E8%BF%9B%E9%98%B6%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>进阶篇</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E9%BB%91%E9%A9%AC%E5%A4%B4%E6%9D%A1/%E8%BF%9B%E9%98%B6%E7%AF%872.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>进阶篇2</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-2 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E9%BB%91%E9%A9%AC%E5%A4%B4%E6%9D%A1/%E9%AB%98%E7%BA%A7%E7%AF%87.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>高级篇</p><!--]--></a><!----></div><!----></div><!--]--></div></section><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E6%94%AF%E4%BB%98.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>支付</p><!--]--></a><!----></div><!----></div><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/%E9%A1%B9%E7%9B%AE%E6%8E%A8%E8%8D%90.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>项目推荐</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><div class="group" data-v-845b8fc6><section class="VPSidebarItem level-0" data-v-845b8fc6 data-v-9b797284><!----><div class="items" data-v-9b797284><!--[--><div class="VPSidebarItem level-1 is-link" data-v-9b797284 data-v-9b797284><div class="item" data-v-9b797284><div class="indicator" data-v-9b797284></div><a class="VPLink link link" href="/notebook/team.html" data-v-9b797284><!--[--><p class="text" data-v-9b797284>团队成员</p><!--]--></a><!----></div><!----></div><!--]--></div></section></div><!--]--><!--[--><!--]--></nav></aside><div class="VPContent has-sidebar" id="VPContent" data-v-255ec12d data-v-669faec9><div class="VPDoc has-sidebar has-aside" data-v-669faec9 data-v-6b87e69f><!--[--><!--]--><div class="container" data-v-6b87e69f><div class="aside" data-v-6b87e69f><div class="aside-curtain" data-v-6b87e69f></div><div class="aside-container" data-v-6b87e69f><div class="aside-content" data-v-6b87e69f><div class="VPDocAside" data-v-6b87e69f data-v-3f215769><!--[--><!--]--><!--[--><!--]--><div class="VPDocAsideOutline" data-v-3f215769 data-v-ff0f39c8><div class="content" data-v-ff0f39c8><div class="outline-marker" data-v-ff0f39c8></div><div class="outline-title" data-v-ff0f39c8>On this page</div><nav aria-labelledby="doc-outline-aria-label" data-v-ff0f39c8><span class="visually-hidden" id="doc-outline-aria-label" data-v-ff0f39c8> Table of Contents for current page </span><ul class="root" data-v-ff0f39c8 data-v-d0ee3533><!--[--><!--]--></ul></nav></div></div><!--[--><!--]--><div class="spacer" data-v-3f215769></div><!--[--><!--]--><!----><!--[--><!--]--><!--[--><!--]--></div></div></div></div><div class="content" data-v-6b87e69f><div class="content-container" data-v-6b87e69f><!--[--><!--]--><!----><main class="main" data-v-6b87e69f><div style="position:relative;" class="vp-doc _notebook_%E4%BA%91%E5%8E%9F%E7%94%9F_Docker" data-v-6b87e69f><div><h1 id="基础知识" tabindex="-1">基础知识 <a class="header-anchor" href="#基础知识" aria-label="Permalink to &quot;基础知识&quot;">​</a></h1><h2 id="docker概述" tabindex="-1">Docker概述 <a class="header-anchor" href="#docker概述" aria-label="Permalink to &quot;Docker概述&quot;">​</a></h2><p>Docker是一个开源的应用容器引擎，让开发者可以打包应用及依赖包到一个可移植的镜像中，然后发布到任何流行的Linux或Windows机器上。使用Docker可以更方便地打包、测试以及部署应用程序。</p><p>微服务虽然具备各种各样的优势，但服务的拆分通用给部署带来了很大的麻烦。</p><ul><li><p>分布式系统中，依赖的组件非常多，不同组件之间部署时往往会产生一些冲突。</p></li><li><p>在数百上千台服务中重复部署，环境不一定一致，会遇到各种问题</p></li><li><p>Docker 是一个开源的应用容器引擎，基于go 语言开发并遵循了apache2.0 协议开源</p></li><li><p>Docker 是在Linux 容器里运行应用的开源工具，是一种轻量级的“虚拟机”</p></li><li><p>Docker 的容器技术可以在一台主机上轻松为任何应用创建一个轻量级的，可移植的，自给自足的容器</p></li></ul><p>也可以这样形象的比喻：</p><blockquote><p>Docker 的Logo设计为蓝色鲸鱼，拖着许多集装箱，鲸鱼可以看作为宿主机，集装箱可以理解为相互隔离的容器，每个集装箱中都包含自己的应用程序。</p></blockquote><h3 id="docker的优点" tabindex="-1">Docker的优点 <a class="header-anchor" href="#docker的优点" aria-label="Permalink to &quot;Docker的优点&quot;">​</a></h3><p>容器化越来越受欢迎，Docker的容器有点总结如下：</p><ul><li>灵活：即使是最复杂的应用也可以集装箱化。</li><li>轻量级：容器利用并共享主机内核。</li><li>可互换：可以即时部署更新和升级。</li><li>便携式：可以在本地构建，部署到云，并在任何地方运行。</li><li>可扩展：可以增加并白动分发容器副本。</li><li>可堆叠：可以垂直和即时堆叠服务。</li></ul><p>Docker 是一个用于开发，交付和运行应用程序的开放平台。Docker 使您能够将应用程序与基础架构分开，从而可以快速交付软件。借助 Docker，您可以与管理应用程序相同的方式来管理基础架构。通过利用 Docker 的方法来快速交付，测试和部署代码，您可以大大减少编写代码和在生产环境中运行代码之间的延迟。</p><h3 id="应用部署的环境问题" tabindex="-1">应用部署的环境问题 <a class="header-anchor" href="#应用部署的环境问题" aria-label="Permalink to &quot;应用部署的环境问题&quot;">​</a></h3><p>大型项目组件较多，运行环境也较为复杂，部署时会碰到一些问题：</p><ul><li><p>依赖关系复杂，容易出现兼容性问题</p></li><li><p>开发、测试、生产环境有差异</p></li></ul><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011022297.png" alt="image-20210731141907366" style="zoom:33%;"><p>例如一个项目中，部署时需要依赖于node.js、Redis、RabbitMQ、MySQL等，这些服务部署时所需要的函数库、依赖项各不相同，甚至会有冲突。给部署带来了极大的困难。</p><h3 id="docker解决依赖兼容问题" tabindex="-1">Docker解决依赖兼容问题 <a class="header-anchor" href="#docker解决依赖兼容问题" aria-label="Permalink to &quot;Docker解决依赖兼容问题&quot;">​</a></h3><p>而Docker确巧妙的解决了这些问题，Docker是如何实现的呢？</p><p>Docker为了解决依赖的兼容问题的，采用了两个手段：</p><ul><li><p>将应用的Libs（函数库）、Deps（依赖）、配置与应用一起打包</p></li><li><p>将每个应用放到一个隔离<strong>容器</strong>去运行，避免互相干扰</p></li></ul><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011022297.png" alt="image-20210731142219735" style="zoom:33%;"><p>这样打包好的应用包中，既包含应用本身，也保护应用所需要的Libs、Deps，无需再操作系统上安装这些，自然就不存在不同应用之间的兼容问题了。虽然解决了不同应用的兼容问题，但是开发、测试等环境会存在差异，操作系统版本也会有差异，怎么解决这些问题呢？</p><h3 id="docker解决操作系统环境差异" tabindex="-1">Docker解决操作系统环境差异 <a class="header-anchor" href="#docker解决操作系统环境差异" aria-label="Permalink to &quot;Docker解决操作系统环境差异&quot;">​</a></h3><p>要解决不同操作系统环境差异问题，必须先了解操作系统结构。以一个Ubuntu操作系统为例，结构如下：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011022303.png" alt="image-20210731143401460" style="zoom:25%;"><p>结构包括：</p><ul><li>计算机硬件：例如CPU、内存、磁盘等</li><li>系统内核：所有Linux发行版的内核都是Linux，例如CentOS、Ubuntu、Fedora等。内核可以与计算机硬件交互，对外提供<strong>内核指令</strong>，用于操作计算机硬件。</li><li>系统应用：操作系统本身提供的应用、函数库。这些函数库是对内核指令的封装，使用更加方便。</li></ul><p>应用于计算机交互的流程如下：</p><p>1）应用调用操作系统应用（函数库），实现各种功能</p><p>2）系统函数库是对内核指令集的封装，会调用内核指令</p><p>3）内核指令操作计算机硬件</p><p>Ubuntu和CentOSpringBoot都是基于Linux内核，无非是系统应用不同，提供的函数库有差异：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011022307.png" alt="image-20210731144304990" style="zoom:25%;"><p>此时，如果将一个Ubuntu版本的MySQL应用安装到CentOS系统，MySQL在调用Ubuntu函数库时，会发现找不到或者不匹配，就会报错了：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011022315.png" alt="image-20210731144458680" style="zoom:25%;"><p>Docker如何解决不同系统环境的问题？</p><ul><li>Docker将用户程序与所需要调用的系统(比如Ubuntu)函数库一起打包</li><li>Docker运行到不同操作系统时，直接基于打包的函数库，借助于操作系统的Linux内核来运行</li></ul><p>如图：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011022312.png" alt="image-20210731144820638" style="zoom:25%;"><p><strong>Docker如何解决大型项目依赖关系复杂，不同组件依赖的兼容性问题？</strong></p><blockquote><ul><li>Docker允许开发中将<strong>应用、依赖、函数库、配置</strong>一起<strong>打包</strong>，形成<strong>可移植镜像</strong></li><li>Docker应用<strong>运行在容器中，使用沙箱机制</strong>，相互<strong>隔离</strong></li></ul></blockquote><p><strong>Docker如何解决开发、测试、生产环境有差异的问题？</strong></p><blockquote><p>Docker镜像中包含完整运行环境，包括系统函数库，<strong>仅依赖系统的Linux内核，因此可以在任意Linux操作系统上运行</strong></p></blockquote><p><strong>Docker是一个快速交付应用、运行应用的技术，具备下列优势：</strong></p><blockquote><ul><li>可以将程序及其依赖、运行环境一起打包为一个镜像，可以迁移到任意Linux操作系统</li><li>运行时利用沙箱机制形成隔离容器，各个应用互不干扰</li><li>启动、移除都可以通过一行命令完成，方便快捷</li></ul></blockquote><h3 id="docker与虚拟机" tabindex="-1">Docker与虚拟机 <a class="header-anchor" href="#docker与虚拟机" aria-label="Permalink to &quot;Docker与虚拟机&quot;">​</a></h3><blockquote><p>虚拟机（virtual machine）是在操作系统中模拟硬件设备，然后运行另一个操作系统，比如在 Windows 系统里面运行 Ubuntu 系统，这样就可以运行任意的Ubuntu应用了。</p></blockquote><blockquote><p>Docker是一个系统进程；虚拟机是在操作系统中的操作系统</p><p>Docker体积小、启动速度快、性能好；虚拟机体积大、启动速度慢、性能一般</p></blockquote><p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202306061506675.png" alt="image-20230606150609557"></p><blockquote><p>容器会在开发环境中取代虚拟机吗？似乎已经有定论了。但是容器会全面取代虚拟机吗？</p><p>开发者不会再像以前那样构建一个单一的应用。通过使用容器，他们能够从以前环境的不一致中解脱出来，更多地关注在代码构建、创建更好的软件以及更快速地编写代码。容器在开发者中已经成为了一种主流的虚拟化技术。</p></blockquote><blockquote><p>但是，容器究竟是应用程序的传递还是基础结构，两者有很大的区别。虚拟机运行缓慢、可移植性较差而且很重，但在部署企业的基础设施和运行传统单体应用时，虚拟机依然是优先考虑的技术。比如，尽管容器是应用程序开发的首选技术，但其他领域的 IT 团队，比如教育行业，不大会愿意花时间来将其定制化的学生信息系统重构为微服务架构，这些企业也无法用一个容器来取代其为学生提供的数以千计的虚拟机。最终答案是什么？在当今的数据中心里，容器和虚拟机器都占有一席之地。</p></blockquote><h3 id="docker架构" tabindex="-1">Docker架构 <a class="header-anchor" href="#docker架构" aria-label="Permalink to &quot;Docker架构&quot;">​</a></h3><h4 id="镜像和容器" tabindex="-1">镜像和容器 <a class="header-anchor" href="#镜像和容器" aria-label="Permalink to &quot;镜像和容器&quot;">​</a></h4><blockquote><p>镜像（<code>Image</code>）：<strong>Docker 镜像是一个特殊的文件系统，除了提供容器运行时所需的程序、库、资源、配置等文件外，还包含了一些为运行时准备的一些配置参数（如匿名卷、环境变量、用户等）。镜像不包含任何动态数据，其内容在构建之后也不会被改变</strong>。</p></blockquote><blockquote><p>容器（<code>Container</code>）：镜像（<code>Image</code>）和容器（<code>Container</code>）的关系，就像是面向对象程序设计中的 <code>类</code> 和 <code>实例</code> 一样，镜像是静态的定义，容器是镜像运行时的实体。容器可以被创建、启动、停止、删除、暂停等。</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011051610.png" alt="image-20220901105139518" style="zoom:67%;"><h4 id="dockerhub仓库" tabindex="-1">DockerHub仓库 <a class="header-anchor" href="#dockerhub仓库" aria-label="Permalink to &quot;DockerHub仓库&quot;">​</a></h4><p>仓库（<code>Repository</code>）：仓库（<code>Repository</code>）类似Git的远程仓库，集中存放镜像文件。最大的公开仓库是 Docker Hub(<a href="https://hub.docker.com/" target="_blank" rel="noreferrer">https://hub.docker.com/</a>)</p><p>开源应用程序非常多，打包这些应用往往是重复的劳动。为了避免这些重复劳动，人们就会将自己打包的应用镜像，例如Redis、MySQL镜像放到网络上，共享使用，就像GitHub的代码共享一样。</p><ul><li><p>DockerHub：DockerHub是一个官方的Docker镜像的托管平台。这样的平台称为Docker Registry。</p></li><li><p>国内也有类似于DockerHub 的公开服务，比如 <a href="https://c.163yun.com/hub" target="_blank" rel="noreferrer">网易云镜像服务</a>、<a href="https://cr.console.aliyun.com/" target="_blank" rel="noreferrer">阿里云镜像库</a>等。</p></li></ul><p>我们一方面可以将自己的镜像共享到DockerHub，另一方面也可以从DockerHub拉取镜像：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011053345.png" style="zoom:67%;"><h4 id="docker架构-1" tabindex="-1">Docker架构 <a class="header-anchor" href="#docker架构-1" aria-label="Permalink to &quot;Docker架构&quot;">​</a></h4><p>我们要使用Docker来操作镜像、容器，就必须要安装Docker。</p><p>Docker是一个CS架构的程序，由两部分组成：</p><blockquote><ul><li><p>服务端(server)：Docker守护进程，负责处理Docker指令，管理镜像、容器等</p></li><li><p>客户端(client)：通过命令或RestAPI向Docker服务端发指令。可以在本地或远程向服务端发送指令</p></li></ul></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011054140.png" alt="image-20220901105403029" style="zoom:80%;"><h2 id="docker-安装、卸载、镜像加速" tabindex="-1">Docker 安装、卸载、镜像加速 <a class="header-anchor" href="#docker-安装、卸载、镜像加速" aria-label="Permalink to &quot;Docker 安装、卸载、镜像加速&quot;">​</a></h2><h3 id="centos安装" tabindex="-1">centos安装 <a class="header-anchor" href="#centos安装" aria-label="Permalink to &quot;centos安装&quot;">​</a></h3><h4 id="安装" tabindex="-1">安装 <a class="header-anchor" href="#安装" aria-label="Permalink to &quot;安装&quot;">​</a></h4><p>安装<code>yum-utils</code>；</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">yum install </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">y yum</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">utils device</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">mapper</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">persistent</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">data lvm2</span></span></code></pre></div><p>为yum源添加docker仓库位置；</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">yum</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">config</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">manager </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">add</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">repo https:</span><span style="color:#89DDFF;">//</span><span style="color:#A6ACCD;">download</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">docker</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">com</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">linux</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">centos</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">ce</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">repo</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span></span>
<span class="line"><span style="color:#A6ACCD;">sed </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">i </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">s/download.docker.com/mirrors.aliyun.com\/docker-ce/g</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">yum</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">repos</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">d</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">ce</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">repo</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">yum makecache fast</span></span></code></pre></div><p>安装docker服务；</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">yum install </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">y docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">ce</span></span></code></pre></div><p>启动docker服务。</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">systemctl start docker</span></span>
<span class="line"><span style="color:#A6ACCD;">systemctl enable docker</span></span></code></pre></div><h4 id="卸载" tabindex="-1">卸载 <a class="header-anchor" href="#卸载" aria-label="Permalink to &quot;卸载&quot;">​</a></h4><p>如果之前安装过旧版本的Docker，可以使用下面命令卸载：</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">yum remove docker </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">                  docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">client </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">                  docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">client</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">latest </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">                  docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">common </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">                  docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">latest </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">                  docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">latest</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">logrotate </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">                  docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">logrotate </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">                  docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">selinux </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">                  docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">engine</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">selinux </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">                  docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">engine </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">                  docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">ce</span></span></code></pre></div><h4 id="存储位置" tabindex="-1">存储位置 <a class="header-anchor" href="#存储位置" aria-label="Permalink to &quot;存储位置&quot;">​</a></h4><p>默认情况下 Docker的存放位置为：<code>/var/lib/docker</code></p><p>可以通过命令查看具体位置：<code>docker info | grep “Docker Root Dir”</code></p><p>修改到其它目录</p><p>首先停掉 Docker 服务：</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">systemctl stop docker</span></span></code></pre></div><p>然后移动整个/var/lib/docker 目录到目的路径</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mkdir -p /root/data/docker</span></span>
<span class="line"><span style="color:#A6ACCD;">mv /var/lib/docker /root/data/docker</span></span>
<span class="line"><span style="color:#A6ACCD;">ln -s /root/data/docker /var/lib/docker --快捷方式</span></span></code></pre></div><h4 id="配置镜像加速" tabindex="-1">配置镜像加速 <a class="header-anchor" href="#配置镜像加速" aria-label="Permalink to &quot;配置镜像加速&quot;">​</a></h4><p>docker官方镜像仓库网速较差，我们需要设置国内镜像服务：</p><p>参考阿里云的镜像加速文档：<a href="https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors" target="_blank" rel="noreferrer">https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors</a></p><p>登录阿里云-----&gt;产品---&gt;弹性计算----&gt;容器镜像服务----&gt;镜像工具------&gt;镜像加速器</p><p>执行步骤:直接复制到terminal中执行就行，包括EOF</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">sudo mkdir </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">docker</span></span>
<span class="line"><span style="color:#A6ACCD;">sudo tee </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">docker</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">daemon</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">json </span><span style="color:#89DDFF;">&lt;&lt;-</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">EOF</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">registry-mirrors</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;">: [</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">https://hi7nmgjd.mirror.aliyuncs.com</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;">]</span></span>
<span class="line"><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#A6ACCD;">EOF</span></span>
<span class="line"><span style="color:#A6ACCD;">sudo systemctl daemon</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">reload</span></span>
<span class="line"><span style="color:#A6ACCD;">sudo systemctl restart docker</span></span></code></pre></div><h3 id="ubuntu安装" tabindex="-1">ubuntu安装 <a class="header-anchor" href="#ubuntu安装" aria-label="Permalink to &quot;ubuntu安装&quot;">​</a></h3><p>1.先卸载旧版，如果没有的话，就不用执行了，直接第二步。</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">apt-get</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">remove</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker-engine</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker.io</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">containerd</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">runc</span></span></code></pre></div><p>2.在终端输入</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">apt</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">update</span></span>
<span class="line"><span style="color:#FFCB6B;">apt-get</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">install</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">ca-certificates</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">curl</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">gnupg</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">lsb-release</span></span></code></pre></div><p>3.安装证书</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">curl</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-fsSL</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> </span><span style="color:#FFCB6B;">sudo</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">apt-key</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">add</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-</span></span></code></pre></div><p>4.写入软件源信息</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">sudo</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">add-apt-repository</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu </span><span style="color:#89DDFF;">$(</span><span style="color:#FFCB6B;">lsb_release</span><span style="color:#C3E88D;"> -cs</span><span style="color:#89DDFF;">)</span><span style="color:#C3E88D;"> stable</span><span style="color:#89DDFF;">&quot;</span></span></code></pre></div><p><img src="https://img-blog.csdnimg.cn/94f498e3a49f40b0b5adebf848406d78.png" alt="img"></p><p>5.安装</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">sudo</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">apt-get</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">install</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker-ce</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker-ce-cli</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">containerd.io</span></span></code></pre></div><p>中途出现问题的话，使用 sudo apt-get update 试试</p><p>6.启动docker</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">systemctl</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">start</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker</span></span>
<span class="line"><span style="color:#FFCB6B;">systemctl</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">enable</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker</span></span></code></pre></div><p>7.安装工具</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">apt-get</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-y</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">install</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">apt-transport-https</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">ca-certificates</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">curl</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">software-properties-common</span></span></code></pre></div><p>8.重启docker</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">service</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">restart</span></span></code></pre></div><p>9.测试是否成功，输入sudo docker run hello-world 显示以下信息则成功，第一次比较慢。</p><p>10.查看docker版本</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">sudo</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">version</span></span></code></pre></div><p>11.查看镜像，可以看到刚才创建的镜像</p><div class="language-cobol"><button title="Copy Code" class="copy"></button><span class="lang">cobol</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">sudo docker images</span></span></code></pre></div><p>12.配置镜像加速</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">sudo</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mkdir</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/etc/docker</span></span>
<span class="line"><span style="color:#FFCB6B;">sudo</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">tee</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/etc/docker/daemon.json</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&lt;&lt;-</span><span style="color:#A6ACCD;">&#39;</span><span style="color:#89DDFF;">EOF</span><span style="color:#A6ACCD;">&#39;</span></span>
<span class="line"><span style="color:#C3E88D;">{</span></span>
<span class="line"><span style="color:#C3E88D;">  &quot;registry-mirrors&quot;: [&quot;https://hi7nmgjd.mirror.aliyuncs.com&quot;]</span></span>
<span class="line"><span style="color:#C3E88D;">}</span></span>
<span class="line"><span style="color:#89DDFF;">EOF</span></span>
<span class="line"><span style="color:#FFCB6B;">sudo</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">systemctl</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">daemon-reload</span></span>
<span class="line"><span style="color:#FFCB6B;">sudo</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">systemctl</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">restart</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker</span></span></code></pre></div><h2 id="docker-compose-安装、卸载" tabindex="-1">Docker compose 安装、卸载 <a class="header-anchor" href="#docker-compose-安装、卸载" aria-label="Permalink to &quot;Docker compose 安装、卸载&quot;">​</a></h2><p>安装：<a href="https://docs.docker.com/compose/install/" target="_blank" rel="noreferrer">https://docs.docker.com/compose/install/</a></p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># Compose目前已经完全支持Linux、Mac OS和Windows，在我们安装Compose之前，需要先安装Docker。下面我 们以编译好的二进制包方式安装在Linux系统中。 </span></span>
<span class="line"><span style="color:#FFCB6B;">curl</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-L</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">https://github.com/docker/compose/releases/download/1.28.6/docker-compose-</span><span style="color:#89DDFF;">$(</span><span style="color:#FFCB6B;">uname</span><span style="color:#C3E88D;"> -s</span><span style="color:#89DDFF;">)</span><span style="color:#C3E88D;">-</span><span style="color:#89DDFF;">$(</span><span style="color:#FFCB6B;">uname</span><span style="color:#C3E88D;"> -m</span><span style="color:#89DDFF;">)&quot;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-o</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/usr/local/bin/docker-compose</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 设置文件可执行权限 </span></span>
<span class="line"><span style="color:#FFCB6B;">sudo</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">chmod</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">+x</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/usr/local/bin/docker-compose</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 查看版本信息 </span></span>
<span class="line"><span style="color:#FFCB6B;">docker-compose</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-version</span></span></code></pre></div><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 二进制包方式安装的，删除二进制文件即可</span></span>
<span class="line"><span style="color:#FFCB6B;">rm</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/usr/local/bin/docker-compose</span></span></code></pre></div><h1 id="应用场景" tabindex="-1">应用场景 <a class="header-anchor" href="#应用场景" aria-label="Permalink to &quot;应用场景&quot;">​</a></h1><h2 id="_1、简化配置" tabindex="-1">1、简化配置 <a class="header-anchor" href="#_1、简化配置" aria-label="Permalink to &quot;1、简化配置&quot;">​</a></h2><blockquote><p>这是Docker公司宣传的Docker的主要使用场景。虚拟机的最大好处是能在你的硬件设施上运行各种配置不一样的平台（软件、系统），Docker在降低额外开销的情况下提供了同样的功能。</p></blockquote><blockquote><p>它能让你将运行环境和配置放在代码中然后部署，同一个Docker的配置可以在不同的环境中使用，这样就降低了硬件要求和应用环境之间耦合度。</p></blockquote><blockquote><ul><li>Web 应用的自动化打包和发布。</li><li>自动化测试和持续集成、发布。</li><li>在服务型环境中部署和调整数据库或其他的后台应用。</li><li>从头编译或者扩展现有的 OpenShift 或 Cloud Foundry 平台来搭建自己的 PaaS 环境。</li></ul></blockquote><blockquote><p>在容器技术出现之前，公司往往是通过为每个开发人员提供一台或者多台虚拟机来充当开发测试环境。开发测试环境一般负载较低，大量的系统资源都被浪费在虚拟机本身的进程上了。</p></blockquote><blockquote><p>Docker容器没有任何CPU和内存上的额外开销，很适合用来提供公司内部的开发测试环境。而且由于docker镜像可以很方便的在公司内部分享，这对开发环境的规范性也有极大的帮助。</p></blockquote><blockquote><p>如果要把容器作为开发机使用，需要解决的是远程登录容器和容器内进程管理问题。虽然docker的初衷是为“微服务”架构设计的，但根据我们的实际使用经验，在docker内运行多个程序，甚至sshd或者upstart也是可行的。</p></blockquote><h2 id="_2、代码流水线管理" tabindex="-1">2、代码流水线管理 <a class="header-anchor" href="#_2、代码流水线管理" aria-label="Permalink to &quot;2、代码流水线管理&quot;">​</a></h2><blockquote><p>前一个场景对于管理代码的流水线起到了很大的帮助。代码从开发者的机器到最终在生产环境上的部署，需要经过很多的中间环境。而每一个中间环境都有自己微小的差别，Docker给应用提供了一个从开发到上线均一致的环境，让代码的流水线变得简单不少。</p></blockquote><h2 id="_3、提高开发效率" tabindex="-1">3、提高开发效率 <a class="header-anchor" href="#_3、提高开发效率" aria-label="Permalink to &quot;3、提高开发效率&quot;">​</a></h2><blockquote><p>这就带来了一些额外的好处：Docker能提升开发者的开发效率。如果你想看一个详细一点的例子，可以参考Aater在DevOpsDays Austin 2014大会或者是DockerCon上的演讲：</p></blockquote><blockquote><p>不同的开发环境中，我们都想把两件事做好。一是我们想让开发环境尽量贴近生产环境，二是我们想快速搭建开发环境。理想状态中，要达到第一个目标，我们需要将每一个服务都跑在独立的虚拟机中以便监控生产环境中服务的运行状态。然而，我们却不想每次都需要网络连接，每次重新编译的时候远程连接上去特别麻烦。</p></blockquote><blockquote><p>这就是Docker做的特别好的地方，开发环境的机器通常内存比较小，之前使用虚拟的时候，我们经常需要为开发环境的机器加内存，而现在Docker可以轻易的让几十个服务在Docker中跑起来。</p></blockquote><h2 id="_4、隔离应用" tabindex="-1">4、隔离应用 <a class="header-anchor" href="#_4、隔离应用" aria-label="Permalink to &quot;4、隔离应用&quot;">​</a></h2><blockquote><p>有很多种原因会让你选择在一个机器上运行不同的应用，比如之前提到的提高开发效率的场景等。</p></blockquote><blockquote><p>我们经常考虑两点，一是因为要降低成本而进行服务器整合，二是将一个整体式的应用拆分成松耦合的单个服务</p></blockquote><h2 id="_5、整合服务器" tabindex="-1">5、整合服务器 <a class="header-anchor" href="#_5、整合服务器" aria-label="Permalink to &quot;5、整合服务器&quot;">​</a></h2><blockquote><p>正如通过虚拟机来整合多个应用，Docker隔离应用的能力使得Docker可以整合多个服务器以降低成本。</p></blockquote><blockquote><p>由于没有多个操作系统的内存占用，以及能在多个实例之间共享没有使用的内存，Docker可以比虚拟机提供更好的服务器整合解决方案。</p></blockquote><h2 id="_6、调试能力" tabindex="-1">6、调试能力 <a class="header-anchor" href="#_6、调试能力" aria-label="Permalink to &quot;6、调试能力&quot;">​</a></h2><blockquote><p>Docker提供了很多的工具，这些工具不一定只是针对容器，但是却适用于容器。它们提供了很多的功能，包括可以为容器设置检查点、设置版本和查看两个容器之间的差别，这些特性可以帮助调试Bug。</p></blockquote><h2 id="_7、多租户环境" tabindex="-1">7、多租户环境 <a class="header-anchor" href="#_7、多租户环境" aria-label="Permalink to &quot;7、多租户环境&quot;">​</a></h2><blockquote><p>另外一个Docker有意思的使用场景是在多租户的应用中，它可以避免关键应用的重写。我们一个特别的关于这个场景的例子是为IoT（译者注：物联网）的应用开发一个快速、易用的多租户环境。这种多租户的基本代码非常复杂，很难处理，重新规划这样一个应用不但消耗时间，也浪费金钱。</p></blockquote><blockquote><p>使用Docker，可以为每一个租户的应用层的多个实例创建隔离的环境，这不仅简单而且成本低廉，当然这一切得益于Docker环境的启动速度和其高效的diff命令。</p></blockquote><h2 id="_8、快速开发" tabindex="-1">8、快速开发 <a class="header-anchor" href="#_8、快速开发" aria-label="Permalink to &quot;8、快速开发&quot;">​</a></h2><blockquote><p>在虚拟机之前，引入新的硬件资源需要消耗几天的时间。Docker的虚拟化技术将这个时间降到了几分钟，Docker只是创建一个容器进程而无需启动操作系统，这个过程只需要秒级的时间。这正是Google和Facebook都看重的特性。</p></blockquote><blockquote><p>你可以在数据中心创建销毁资源而无需担心重新启动带来的开销。通常数据中心的资源利用率只有30%，通过使用Docker并进行有效的资源分配可以提高资源的利用率。</p></blockquote><h1 id="常用命令" tabindex="-1">常用命令 <a class="header-anchor" href="#常用命令" aria-label="Permalink to &quot;常用命令&quot;">​</a></h1><h2 id="启动、停止、状态" tabindex="-1">启动、停止、状态 <a class="header-anchor" href="#启动、停止、状态" aria-label="Permalink to &quot;启动、停止、状态&quot;">​</a></h2><p>Docker应用需要用到各种端口，逐一去修改防火墙设置。非常麻烦，因此建议大家直接关闭防火墙！</p><p>启动docker前，一定要关闭防火墙后！！</p><p>启动docker前，一定要关闭防火墙后！！</p><p>启动docker前，一定要关闭防火墙后！！</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 关闭</span></span>
<span class="line"><span style="color:#A6ACCD;">systemctl stop firewalld</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 禁止开机启动防火墙</span></span>
<span class="line"><span style="color:#A6ACCD;">systemctl disable firewalld</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 启动docker： </span></span>
<span class="line"><span style="color:#A6ACCD;">systemctl start docker</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 停止docker： </span></span>
<span class="line"><span style="color:#A6ACCD;">systemctl stop docker</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 重启docker： </span></span>
<span class="line"><span style="color:#A6ACCD;">systemctl restart docker</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 查看docker状态： </span></span>
<span class="line"><span style="color:#A6ACCD;">systemctl status docker</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 开机启动： </span></span>
<span class="line"><span style="color:#A6ACCD;">systemctl enable docker</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 查看docker概要信息： 包括镜像、容器数、系统信息等</span></span>
<span class="line"><span style="color:#A6ACCD;">docker info</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 显示 Docker 版本信息。</span></span>
<span class="line"><span style="color:#A6ACCD;">docker version  </span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 查看docker总体帮助文档： </span></span>
<span class="line"><span style="color:#A6ACCD;">docker </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">help</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 查看docker命令帮助文档： </span></span>
<span class="line"><span style="color:#A6ACCD;">docker 具体命令 </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">help，docker </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">help，docker run </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">help</span></span></code></pre></div><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 查看镜像/容器/数据卷所占的空间</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">system</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">df</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 查看指定容器资源占用状况，比如cpu、内存、网络、io状态：</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">stats</span><span style="color:#A6ACCD;"> $ContainerName</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 查看所有容器资源占用情况：</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">stats</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-a</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220207130306284.png" alt="image-20220207130306284" style="zoom:80%;"><h2 id="镜像命令" tabindex="-1">镜像命令 <a class="header-anchor" href="#镜像命令" aria-label="Permalink to &quot;镜像命令&quot;">​</a></h2><h3 id="镜像图解" tabindex="-1">镜像图解 <a class="header-anchor" href="#镜像图解" aria-label="Permalink to &quot;镜像图解&quot;">​</a></h3><p>首先来看下镜像的名称组成：</p><blockquote><ul><li>镜名称一般分两部分组成：[repository]:[tag]。</li><li>在没有指定tag时，默认是latest，代表最新版本的镜像</li></ul></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011112321.png" alt="image-20220901111247246" style="zoom:67%;"><blockquote><p>这里的mysql就是repository，5.7就是tag，合一起就是镜像名称，代表5.7版本的MySQL镜像。</p></blockquote><p>常见的镜像操作命令如图：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011113798.png" alt="image-20220901111332707" style="zoom:80%;"><h3 id="查看本地镜像" tabindex="-1">查看本地镜像 <a class="header-anchor" href="#查看本地镜像" aria-label="Permalink to &quot;查看本地镜像&quot;">​</a></h3><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">images</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># -a :列出本地所有的镜像（含历史映像层） -q :只显示镜像ID</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">images</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-aq</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220207120702038.png" alt="image-20220207120702038" style="zoom:80%;"><blockquote><ul><li>REPOSITORY：表示镜像的仓库源</li><li>TAG：镜像的标签版本号</li><li>IMAGE ID：镜像ID</li><li>CREATED：镜像创建时间</li><li>SIZE：镜像大小</li></ul></blockquote><blockquote><p>同一仓库源可以有多个 TAG版本，代表这个仓库源的不同个版本，我们使用 REPOSITORY:TAG 来定义不同的镜像。如果你不指定一个镜像的版本标签，例如你只使用 ubuntu，将默认使用 ubuntu:latest 镜像</p></blockquote><h3 id="查找-拉取镜像" tabindex="-1">查找 &amp; 拉取镜像 <a class="header-anchor" href="#查找-拉取镜像" aria-label="Permalink to &quot;查找 &amp; 拉取镜像&quot;">​</a></h3><blockquote><p>网站：<a href="https://hub.docker.com" target="_blank" rel="noreferrer">https://hub.docker.com</a></p></blockquote><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">search</span><span style="color:#A6ACCD;"> [OPTIONS] 镜像名字</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># limit : 只列出N个镜像，默认25个</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">search</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--limit</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">5</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">redis</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 注意：没有TAG就是最新版，等价于docker pull 镜像名字:latest。</span></span>
<span class="line"><span style="color:#A6ACCD;">docker pull 镜像名字</span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">:TAG</span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#A6ACCD;">docker pull redis:</span><span style="color:#F78C6C;">6.0.8</span></span>
<span class="line"><span style="color:#A6ACCD;">docker pull ubuntu</span></span>
<span class="line"><span style="color:#A6ACCD;">docker pull nginx</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220207123349500.png" alt="image-20220207123349500" style="zoom:80%;"><blockquote><ul><li>NAME：镜像名称</li><li>DESCRIPTION：镜像说明</li><li>STARS：点赞数量</li><li>OFFICIAL：是否是官方的</li><li>AUTOMATED：是否自动构建的</li></ul></blockquote><h3 id="删除镜像" tabindex="-1">删除镜像 <a class="header-anchor" href="#删除镜像" aria-label="Permalink to &quot;删除镜像&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 删除单个</span></span>
<span class="line"><span style="color:#A6ACCD;">docker rmi  </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f 镜像ID</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 删除多个</span></span>
<span class="line"><span style="color:#A6ACCD;">docker rmi </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f 镜像名</span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;">:TAG 镜像名</span><span style="color:#F78C6C;">2</span><span style="color:#A6ACCD;">:TAG </span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 删除全部</span></span>
<span class="line"><span style="color:#A6ACCD;">docker rmi </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f $</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">docker images </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">qa</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">docker rmi </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f $</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">docker images</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 指定名称删除镜像：</span></span>
<span class="line"><span style="color:#A6ACCD;">docker rmi java:</span><span style="color:#F78C6C;">8</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 指定名称删除镜像（强制）</span></span>
<span class="line"><span style="color:#A6ACCD;">docker rmi </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f java:</span><span style="color:#F78C6C;">8</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 删除所有没有引用的镜像</span></span>
<span class="line"><span style="color:#A6ACCD;">docker rmi `docker images </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> grep none </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> awk </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">{print $3}</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">`</span></span></code></pre></div><h3 id="镜像存放位置" tabindex="-1">镜像存放位置 <a class="header-anchor" href="#镜像存放位置" aria-label="Permalink to &quot;镜像存放位置&quot;">​</a></h3><blockquote><p>查看Docker镜像的存放位置：</p></blockquote><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker info </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> grep </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">Docker Root Dir</span><span style="color:#89DDFF;">&quot;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202208141544838.png" alt="image-20220814154434765" style="zoom:67%;"><blockquote><p>修改镜像存放位置</p></blockquote><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 关闭Docker服务</span></span>
<span class="line"><span style="color:#A6ACCD;">systemctl stop docker</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 先将原镜像目录移动到目标目录</span></span>
<span class="line"><span style="color:#A6ACCD;">mv </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">docker </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydata</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">docker</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 建立软连接</span></span>
<span class="line"><span style="color:#A6ACCD;">ln </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">s </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydata</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">docker </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">docker</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 再次查看可以发现镜像存放位置已经更改。</span></span>
<span class="line"><span style="color:#A6ACCD;">docker info </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> grep </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">Docker Root Dir</span><span style="color:#89DDFF;">&quot;</span></span></code></pre></div><h3 id="虚玄镜像-重要" tabindex="-1">虚玄镜像(重要) <a class="header-anchor" href="#虚玄镜像-重要" aria-label="Permalink to &quot;虚玄镜像(重要)&quot;">​</a></h3><blockquote><p>仓库名、标签都是&lt;none&gt;的镜像，俗称虚悬镜像dangling image.一般都是用Dockerfile创建镜像时，生成none镜像。用docker images查看时发现仓库和tag都是none就是虚悬镜像了。<strong>虚悬镜像一般都要删除</strong></p></blockquote><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 查看虚玄镜像</span></span>
<span class="line"><span style="color:#A6ACCD;">docker image ls </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f dangling</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">true</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 虚悬镜像已经失去存在价值，可以删除</span></span>
<span class="line"><span style="color:#A6ACCD;">docker image prune</span></span></code></pre></div><h3 id="镜像导入、导出、加工⭐" tabindex="-1">镜像导入、导出、加工⭐ <a class="header-anchor" href="#镜像导入、导出、加工⭐" aria-label="Permalink to &quot;镜像导入、导出、加工⭐&quot;">​</a></h3><blockquote><p>需求：利用docker save将nginx镜像导出磁盘，然后再通过load加载回来</p></blockquote><blockquote><p>1）利用docker xx --help命令查看docker save和docker load的语法</p></blockquote><blockquote><p>例如，查看save命令用法，可以输入命令：</p></blockquote><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">save</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--help</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">save</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-o</span><span style="color:#A6ACCD;"> [保存的目标文件名称] </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">镜像名称</span><span style="color:#89DDFF;">]</span></span></code></pre></div><blockquote><p>2）使用docker save导出镜像到磁盘</p></blockquote><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">save</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-o</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx.tar</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx:latest</span></span></code></pre></div><blockquote><p>3）使用docker load加载镜像，先删除本地的nginx镜像：</p></blockquote><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">rmi</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx:latest</span></span></code></pre></div><p>然后运行命令，加载本地文件：</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">load</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-i</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx.tar</span></span></code></pre></div><blockquote><p>4)镜像加工制作</p></blockquote><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> docker commit提交容器副本使之成为一个新的镜像</span></span>
<span class="line"><span style="color:#A6ACCD;">docker commit </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">m</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">提交的描述信息</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">a</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">作者</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;"> 容器ID 要创建的目标镜像名:</span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">标签名</span><span style="color:#89DDFF;">]</span></span></code></pre></div><blockquote><p>进入ubuntu，此时没有vim，<strong>原始的默认Ubuntu镜像是不带着vim命令的</strong></p></blockquote><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-it</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">ubuntu</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">bash</span></span></code></pre></div><p>外网连通的情况下，安装vim</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">apt-get</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">update</span></span>
<span class="line"><span style="color:#FFCB6B;">apt-get</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">install</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">vim</span></span></code></pre></div><p>查看ubuntu容器ID</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">ps</span></span></code></pre></div><p>安装完成后，commit我们自己的新镜像</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">commit</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-m=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">vubantu</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-a=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">renshuo</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">ea633bb26138</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">ubuntupro:2.0</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220207184017528.png" alt="image-20220207184017528" style="zoom:80%;"><p>用这个镜像创建容器，容器已经拥有vim功能了</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-it</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">bc3a8d5b4d88</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">bash</span></span>
<span class="line"><span style="color:#FFCB6B;">vim</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">a.txt</span></span></code></pre></div><h2 id="容器命令" tabindex="-1">容器命令 <a class="header-anchor" href="#容器命令" aria-label="Permalink to &quot;容器命令&quot;">​</a></h2><h3 id="容器图解" tabindex="-1">容器图解 <a class="header-anchor" href="#容器图解" aria-label="Permalink to &quot;容器图解&quot;">​</a></h3><blockquote><p>有镜像才能创建容器，这是根本前提(下载一个CentOS或者ubuntu镜像演示)，容器操作的命令如图：</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011121282.png" alt="image-20210731161950495" style="zoom:50%;"><p>容器保护三个状态：</p><blockquote><ul><li>运行：进程正常运行</li><li>暂停：进程暂停，CPU不再运行，并不释放内存</li><li>停止：进程终止，回收进程占用的内存、CPU等资源</li></ul></blockquote><blockquote><ul><li><p>docker run：创建并运行一个容器，处于运行状态</p></li><li><p>docker pause：让一个运行的容器暂停</p></li><li><p>docker unpause：让一个容器从暂停状态恢复运行</p></li><li><p>docker stop：停止一个运行的容器</p></li><li><p>docker start：让一个停止的容器再次运行</p></li><li><p>docker rm：删除一个容器</p></li></ul></blockquote><h3 id="新建-启动容器" tabindex="-1">新建+启动容器 <a class="header-anchor" href="#新建-启动容器" aria-label="Permalink to &quot;新建+启动容器&quot;">​</a></h3><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> [OPTIONS] IMAGE </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">COMMAND</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">ARG...</span><span style="color:#89DDFF;">]</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 创建一个新的容器但不启动它。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 使用docker镜像nginx:latest创建一个容器,并将容器命名为mynginx  </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">create</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--name</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mynginx</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx:latest</span><span style="color:#A6ACCD;">     </span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 使用docker镜像nginx:latest以后台模式启动一个容器,并将容器命名为mynginx。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 在大部分的场景下，我们希望 docker 的服务是在后台运行的，我们可以过 -d 指定容器的后台运行模式。</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--name</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mynginx</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-d</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx:latest</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 使用镜像 nginx:latest，以后台模式启动一个容器,将容器的 80 端口映射到主机的 80 端口,</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 主机的目录 /data 映射到容器的 /data。  </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">80</span><span style="color:#C3E88D;">:80</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-v</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/data:/data</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-d</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx:latest</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 使用镜像nginx:latest以交互模式启动一个容器,在容器内执行/bin/bash命令。  </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-it</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx:latest</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/bin/bash</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-it</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--name=u1</span><span style="color:#A6ACCD;">  </span><span style="color:#C3E88D;">ubuntu</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/bin/bash</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-it</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">ubuntu</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">bash</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-it</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">centos</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/bin/bash</span></span></code></pre></div><p>OPTIONS说明（常用）</p><blockquote><ul><li><p>--name=&quot;容器新名字&quot;，<strong>为容器指定一个名称，若没有指定名称，则自动生成一个随机名称</strong>；</p></li><li><p>-d: <strong>后台运行容器并返回容器ID，也即启动守护式容器(后台运行)</strong>；</p></li><li><p>-i：<strong>以交互模式运行容器，通常与 -t 同时使用</strong>；</p></li><li><p>-t：<strong>为容器重新分配一个伪输入终端，通常与 -i 同时使用</strong>；也即启动交互式容器</p></li><li><p>-P: 随机端口映射，大写P</p></li><li><p>-p: 指定端口映射，小写p</p></li></ul></blockquote><h3 id="查看容器" tabindex="-1">查看容器 <a class="header-anchor" href="#查看容器" aria-label="Permalink to &quot;查看容器&quot;">​</a></h3><blockquote><ul><li>-a :列出当前所有正在运行的容器+历史上运行过的</li><li>-l :显示最近创建的容器。</li><li>-n：显示最近n个创建的容器。</li><li>-q :静默模式，只显示容器编号。</li></ul></blockquote><blockquote><p>通过该指令查看之前停止的容器，<strong>用docker start等命令可以重启该容器(不用再次创建该容器了)</strong></p></blockquote><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 列出所有在运行的容器信息。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker ps  </span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 列出所有容器</span></span>
<span class="line"><span style="color:#A6ACCD;">docker ps </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">a</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 列出最近创建的</span><span style="color:#F78C6C;">5</span><span style="color:#A6ACCD;">个容器信息。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker ps </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">n </span><span style="color:#F78C6C;">5</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 列出所有创建的容器ID。 </span></span>
<span class="line"><span style="color:#A6ACCD;">docker ps </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">a </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">q </span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 列出指定的容器的端口映射。</span></span>
<span class="line"><span style="color:#A6ACCD;">docker port mymysql</span></span></code></pre></div><h3 id="删除-停止-退出容器" tabindex="-1">删除 &amp; 停止 &amp; 退出容器 <a class="header-anchor" href="#删除-停止-退出容器" aria-label="Permalink to &quot;删除 &amp; 停止 &amp; 退出容器&quot;">​</a></h3><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 根据容器名字杀掉容器  </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">kill</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">tomcat7</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 根据容器ID杀掉容器  </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">kill</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">65</span><span style="color:#C3E88D;">d4a94f7a39</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 删除已停止的容器：</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">rm</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">容器ID</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 一次性删除多个容器实例(所有容器)</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">rm</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-f</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">$(</span><span style="color:#FFCB6B;">docker</span><span style="color:#C3E88D;"> ps -a -q</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">ps</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-a</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-q</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> </span><span style="color:#FFCB6B;">xargs</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">rm</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 退出容器</span></span>
<span class="line"><span style="color:#82AAFF;">exit</span><span style="color:#A6ACCD;">：run进去容器，exit退出，容器停止</span></span>
<span class="line"><span style="color:#FFCB6B;">ctrl+p+q：run进去容器，ctrl+p+q退出，容器不停止</span></span></code></pre></div><h3 id="start-stop-restart" tabindex="-1">start/stop/restart <a class="header-anchor" href="#start-stop-restart" aria-label="Permalink to &quot;start/stop/restart&quot;">​</a></h3><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 启动已被停止的容器mynginx  </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">start</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mynginx</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 停止运行中的容器mynginx  </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">stop</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mynginx</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 重启容器mynginx  </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">restart</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mynginx</span></span></code></pre></div><h3 id="查看容器日志⭐" tabindex="-1">查看容器日志⭐ <a class="header-anchor" href="#查看容器日志⭐" aria-label="Permalink to &quot;查看容器日志⭐&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 持续日志输出，类似tail </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f命令</span></span>
<span class="line"><span style="color:#A6ACCD;">docker logs </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f 容器ID</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 跟踪查看容器mynginx的日志输出。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker logs </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f mynginx  </span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 查看容器mynginx从</span><span style="color:#F78C6C;">2016</span><span style="color:#A6ACCD;">年</span><span style="color:#F78C6C;">7</span><span style="color:#A6ACCD;">月</span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;">日后的最新</span><span style="color:#F78C6C;">10</span><span style="color:#A6ACCD;">条日志。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker logs </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">since</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">2016-07-01</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">tail</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">10</span><span style="color:#A6ACCD;"> mynginx  </span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 带时间戳显示日志</span></span>
<span class="line"><span style="color:#A6ACCD;">docker logs </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">t  nginx1</span></span></code></pre></div><h3 id="进入容器交互" tabindex="-1">进入容器交互 <a class="header-anchor" href="#进入容器交互" aria-label="Permalink to &quot;进入容器交互&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it 容器ID bashShell</span></span>
<span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it 容器ID </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span>
<span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it 容器ID redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">cli</span></span></code></pre></div><p>在运行的容器中执行命令。可选参数：</p><blockquote><ul><li><strong>-d :</strong> <strong>分离模式: 在后台运行，一般用-d后台启动的程序，再用exec进入对应容器实例</strong></li><li><strong>-i :</strong> 即使没有附加也保持STDIN 打开</li><li><strong>-t :</strong> 分配一个伪终端</li></ul></blockquote><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 在容器 mynginx 中以交互模式执行容器内 /root/nginx.sh 脚本  </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">exec</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-it</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mynginx</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/bin/sh</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/root/nginx.sh</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 在容器 mynginx 中开启一个交互模式的终端  </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">exec</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-i</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-t</span><span style="color:#A6ACCD;">  </span><span style="color:#C3E88D;">mynginx</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/bin/bash</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 也可以通过 docker ps -a 命令查看已经在运行的容器，然后使用容器 ID 进入容器。  </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">ps</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-a</span><span style="color:#A6ACCD;">   </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">exec</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-it</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">9</span><span style="color:#C3E88D;">df70f9a0714</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/bin/bash</span></span></code></pre></div><p>命令解读：</p><blockquote><ul><li><p>docker exec ：进入容器内部，执行一个命令</p></li><li><p>-it : 给当前进入的容器创建一个标准输入、输出终端，允许我们与容器交互</p></li><li><p>mn ：要进入的容器的名称</p></li><li><p>bash：进入容器后执行的命令，bash是一个linux终端交互命令</p></li></ul></blockquote><p>容器内部会模拟一个独立的Linux文件系统，看起来如同一个linux服务器一样：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011142164.png" alt="image-20220901114212077" style="zoom:67%;"><blockquote><p>nginx的环境、配置、运行文件全部都在这个文件系统中，包括我们要修改的html文件。查看DockerHub网站中的nginx页面，可以知道nginx的html目录位置在<code>/usr/share/nginx/html</code>我们执行命令，进入该目录：</p></blockquote><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#82AAFF;">cd</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/usr/share/nginx/html</span></span></code></pre></div><p>查看目录下文件：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011142798.png" alt="image-20220901114228725" style="zoom:67%;"><p>3）修改index.html的内容</p><p>容器内没有vi命令，无法直接修改，我们用下面的命令来修改：</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">sed</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-i</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-e</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">s#Welcome to nginx#传智教育欢迎您#g</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-e</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">s#&lt;head&gt;#&lt;head&gt;&lt;meta charset=&quot;utf-8&quot;&gt;#g</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">index.html</span></span></code></pre></div><p>在浏览器访问自己的虚拟机地址，例如我的是：<a href="http://192.168.150.101" target="_blank" rel="noreferrer">http://192.168.150.101</a>，即可看到结果：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011142125.png" alt="image-20220901114254038" style="zoom:67%;"><p>指定账号进入容器内部</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 使用root账号进入容器内部</span></span>
<span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">user root $ContainerName </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span></code></pre></div><p>重新进入</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker attach 容器ID</span></span></code></pre></div><p>案例演示，用centos或者unbuntu都可以</p><ul><li><p>attach 直接进入容器启动命令的终端，不会启动新的进程，用exit退出，会导致容器的停止。</p></li><li><p>exec 是在容器中打开新的终端，<strong>并且可以启动新的进程，用exit退出，不会导致容器的停止</strong>。</p></li></ul><p><strong>推荐大家使用 docker exec 命令，因为退出容器终端，不会导致容器的停止</strong>。</p><p>示例</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;"> 后台启动</span></span>
<span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d redis:</span><span style="color:#F78C6C;">6.0.8</span></span>
<span class="line"><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;"> 查看容器ID</span></span>
<span class="line"><span style="color:#A6ACCD;">docker ps</span></span>
<span class="line"><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;"> 进入redis</span></span>
<span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it e2db0e470d67 redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">cli</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;"> 或者另一种方式进入</span></span>
<span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it e2db0e470d67 </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span>
<span class="line"><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">cli </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">6379</span></span>
<span class="line"><span style="color:#A6ACCD;">set k1 v1</span></span>
<span class="line"><span style="color:#A6ACCD;">get k1</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220207143625748.png" alt="image-20220207143625748" style="zoom:80%;"><h3 id="从容器内拷贝文件到主机上" tabindex="-1">从容器内拷贝文件到主机上 <a class="header-anchor" href="#从容器内拷贝文件到主机上" aria-label="Permalink to &quot;从容器内拷贝文件到主机上&quot;">​</a></h3><p>容器→主机</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker cp 容器ID:容器内路径 目的主机路径</span></span></code></pre></div><p>进入ubuntu容器</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it ubuntu bash</span></span></code></pre></div><p>安装vim编辑器</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">apt-get update</span></span>
<span class="line"><span style="color:#A6ACCD;">apt-get install vim</span></span></code></pre></div><p>创建文件</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">vi test.txt</span></span></code></pre></div><p>进行复制</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker cp </span><span style="color:#F78C6C;">84b15e00abbc</span><span style="color:#A6ACCD;">:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">test</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">txt </span><span style="color:#89DDFF;">/</span></span></code></pre></div><h3 id="导入和导出容器" tabindex="-1">导入和导出容器 <a class="header-anchor" href="#导入和导出容器" aria-label="Permalink to &quot;导入和导出容器&quot;">​</a></h3><blockquote><ul><li>export 导出容器的内容留作为一个tar归档文件[对应import命令]</li><li>import 从tar包中的内容创建一个新的文件系统再导入为镜像[对应export]</li></ul></blockquote><p>容器是正在启动中的，如果关闭了容器，用docker ps -a查看启动的容器ID，然后用docker start 容器ID启动服务，启动完成后执行docker exec进入容器内部</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker export 容器ID </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> 文件名</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">tar</span></span>
<span class="line"><span style="color:#A6ACCD;">cat 文件名</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">tar </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> docker import </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> 镜像用户</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">镜像名:镜像版本号</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker export </span><span style="color:#F78C6C;">84b15e00abbc</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> ubuntuPro</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">tar</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">cat ubuntuPro</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">tar </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> docker import </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> renshuo</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">ubantupro:</span><span style="color:#F78C6C;">1.0</span></span></code></pre></div><p>再进行查看</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker images</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220207172815660.png" alt="image-20220207172815660" style="zoom:80%;"><p>执行自己的镜像创建容器</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it ee13d72866f0 </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220207173123219.png" alt="image-20220207173123219" style="zoom:80%;"><p>这时可以发现test.txt存在于该容器内</p><h3 id="同步宿主机时间到容器" tabindex="-1">同步宿主机时间到容器 <a class="header-anchor" href="#同步宿主机时间到容器" aria-label="Permalink to &quot;同步宿主机时间到容器&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker cp </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">localtime $ContainerName:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span></span></code></pre></div><h3 id="指定容器时区" tabindex="-1">指定容器时区 <a class="header-anchor" href="#指定容器时区" aria-label="Permalink to &quot;指定容器时区&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">80</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">80</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name nginx </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">e TZ</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">Asia/Shanghai</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d nginx:</span><span style="color:#F78C6C;">1.17.0</span></span></code></pre></div><h2 id="网络命令" tabindex="-1">网络命令 <a class="header-anchor" href="#网络命令" aria-label="Permalink to &quot;网络命令&quot;">​</a></h2><h3 id="查看容器的ip地址" tabindex="-1">查看容器的IP地址 <a class="header-anchor" href="#查看容器的ip地址" aria-label="Permalink to &quot;查看容器的IP地址&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker inspect </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">format </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">{{ .NetworkSettings.IPAddress }}</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> $ContainerName</span></span></code></pre></div><h3 id="查看所有网络" tabindex="-1">查看所有网络 <a class="header-anchor" href="#查看所有网络" aria-label="Permalink to &quot;查看所有网络&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker network ls</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202208141546744.png" alt="image-20220814154653670" style="zoom:67%;"><h3 id="创建外部网络" tabindex="-1">创建外部网络 <a class="header-anchor" href="#创建外部网络" aria-label="Permalink to &quot;创建外部网络&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker network create </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d bridge my</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">bridge</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">network</span></span></code></pre></div><h3 id="指定容器网络" tabindex="-1">指定容器网络 <a class="header-anchor" href="#指定容器网络" aria-label="Permalink to &quot;指定容器网络&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">80</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">80</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name nginx </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">network my</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">bridge</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">network </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d nginx:</span><span style="color:#F78C6C;">1.17.0</span></span></code></pre></div><h2 id="容器rootfs命令" tabindex="-1">容器rootfs命令 <a class="header-anchor" href="#容器rootfs命令" aria-label="Permalink to &quot;容器rootfs命令&quot;">​</a></h2><h3 id="commit" tabindex="-1">commit <a class="header-anchor" href="#commit" aria-label="Permalink to &quot;commit&quot;">​</a></h3><p>从容器创建一个新的镜像。参数说明：</p><ul><li><strong>-a :</strong> 提交的镜像作者；</li><li><strong>-c :</strong> 使用Dockerfile指令来创建镜像；</li><li><strong>-m :</strong> 提交时的说明文字；</li><li><strong>-p :</strong> 在commit时，将容器暂停。</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 将容器a404c6c174a2 保存为新的镜像,</span></span>
<span class="line"><span style="color:#A6ACCD;"># 并添加提交人信息和说明信息。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker commit -a &quot;guodong&quot; -m &quot;my db&quot; a404c6c174a2  mymysql:v1</span></span></code></pre></div><h3 id="cp" tabindex="-1">cp <a class="header-anchor" href="#cp" aria-label="Permalink to &quot;cp&quot;">​</a></h3><p>用于容器与主机之间的数据拷贝。参数说明：</p><ul><li><strong>-L :</strong> 保持源目标中的链接</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 将主机/www/runoob目录拷贝到容器96f7f14e99ab的/www目录下。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker cp /www/runoob 96f7f14e99ab:/www/  </span></span>
<span class="line"><span style="color:#A6ACCD;"></span></span>
<span class="line"><span style="color:#A6ACCD;"># 将主机/www/runoob目录拷贝到容器96f7f14e99ab中，目录重命名为www。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker cp /www/runoob 96f7f14e99ab:/www  </span></span>
<span class="line"><span style="color:#A6ACCD;"></span></span>
<span class="line"><span style="color:#A6ACCD;"># 将容器96f7f14e99ab的/www目录拷贝到主机的/tmp目录中。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker cp  96f7f14e99ab:/www /tmp/</span></span></code></pre></div><h3 id="diff" tabindex="-1">diff <a class="header-anchor" href="#diff" aria-label="Permalink to &quot;diff&quot;">​</a></h3><p>检查容器里文件结构的更改。</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight has-diff"><code><span class="line"><span style="color:#A6ACCD;"># 查看容器mymysql的文件结构更改。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker diff mymysql</span></span></code></pre></div><h2 id="镜像仓库命令" tabindex="-1">镜像仓库命令 <a class="header-anchor" href="#镜像仓库命令" aria-label="Permalink to &quot;镜像仓库命令&quot;">​</a></h2><h3 id="login-logout" tabindex="-1">login/logout <a class="header-anchor" href="#login-logout" aria-label="Permalink to &quot;login/logout&quot;">​</a></h3><p><strong>docker login :</strong> 登陆到一个Docker镜像仓库，如果未指定镜像仓库地址，默认为官方仓库 Docker Hub**docker logout 😗*登出一个Docker镜像仓库，如果未指定镜像仓库地址，默认为官方仓库 Docker Hub参数说明：</p><ul><li><strong>-u :</strong> 登陆的用户名</li><li><strong>-p :</strong> 登陆的密码</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 登陆到Docker Hub  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker login -u 用户名 -p 密码  </span></span>
<span class="line"><span style="color:#A6ACCD;"></span></span>
<span class="line"><span style="color:#A6ACCD;"># 登出Docker Hub  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker logout</span></span></code></pre></div><h3 id="pull" tabindex="-1">pull <a class="header-anchor" href="#pull" aria-label="Permalink to &quot;pull&quot;">​</a></h3><p>从镜像仓库中拉取或者更新指定镜像。参数说明：</p><ul><li><strong>-a :</strong> 拉取所有 tagged 镜像</li><li><strong>–disable-content-trust :</strong> 忽略镜像的校验,默认开启</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 从Docker Hub下载java最新版镜像。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker pull java  </span></span>
<span class="line"><span style="color:#A6ACCD;"></span></span>
<span class="line"><span style="color:#A6ACCD;"># 从Docker Hub下载REPOSITORY为java的所有镜像。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker pull -a java</span></span></code></pre></div><h3 id="push" tabindex="-1">push <a class="header-anchor" href="#push" aria-label="Permalink to &quot;push&quot;">​</a></h3><p>将本地的镜像上传到镜像仓库,要先登陆到镜像仓库。参数说明：</p><ul><li><strong>–disable-content-trust :</strong> 忽略镜像的校验,默认开启</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 上传本地镜像myapache:v1到镜像仓库中。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker push myapache:v1</span></span></code></pre></div><h3 id="search" tabindex="-1">search <a class="header-anchor" href="#search" aria-label="Permalink to &quot;search&quot;">​</a></h3><p>从Docker Hub查找镜像。参数说明：</p><ul><li><strong>–automated :</strong> 只列出 automated build类型的镜像；</li><li><strong>–no-trunc :</strong> 显示完整的镜像描述；</li><li><strong>-f &lt;过滤条件&gt;:</strong> 列出指定条件的镜像。</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 从 Docker Hub 查找所有镜像名包含 java，并且收藏数大于 10 的镜像  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker search -f stars=10 java  </span></span>
<span class="line"><span style="color:#A6ACCD;"></span></span>
<span class="line"><span style="color:#A6ACCD;">NAME                  DESCRIPTION                           STARS   OFFICIAL   AUTOMATED  </span></span>
<span class="line"><span style="color:#A6ACCD;">java                  Java is a concurrent, class-based...   1037    [OK]         </span></span>
<span class="line"><span style="color:#A6ACCD;">anapsix/alpine-java   Oracle Java 8 (and 7) with GLIBC ...   115                [OK]  </span></span>
<span class="line"><span style="color:#A6ACCD;">develar/java                                                 46                 [OK]</span></span></code></pre></div><p>每列参数说明：</p><ul><li><strong>NAME:</strong> 镜像仓库源的名称</li><li><strong>DESCRIPTION:</strong> 镜像的描述</li><li><strong>OFFICIAL:</strong> 是否 docker 官方发布</li><li><strong>stars:</strong> 类似 Github 里面的 star，表示点赞、喜欢的意思</li><li><strong>AUTOMATED:</strong> 自动构建</li></ul><h2 id="本地镜像管理命令" tabindex="-1">本地镜像管理命令 <a class="header-anchor" href="#本地镜像管理命令" aria-label="Permalink to &quot;本地镜像管理命令&quot;">​</a></h2><h3 id="images" tabindex="-1">images <a class="header-anchor" href="#images" aria-label="Permalink to &quot;images&quot;">​</a></h3><p>列出本地镜像。参数说明：</p><ul><li><strong>-a :</strong> 列出本地所有的镜像（含中间映像层，默认情况下，过滤掉中间映像层）；</li><li><strong>–digests :</strong> 显示镜像的摘要信息；</li><li><strong>-f :</strong> 显示满足条件的镜像；</li><li><strong>–format :</strong> 指定返回值的模板文件；</li><li><strong>–no-trunc :</strong> 显示完整的镜像信息；</li><li><strong>-q :</strong> 只显示镜像ID。</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 查看本地镜像列表。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker images  </span></span>
<span class="line"><span style="color:#A6ACCD;"></span></span>
<span class="line"><span style="color:#A6ACCD;"># 列出本地镜像中REPOSITORY为ubuntu的镜像列表。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker images  ubuntu</span></span></code></pre></div><h3 id="rmi" tabindex="-1">rmi <a class="header-anchor" href="#rmi" aria-label="Permalink to &quot;rmi&quot;">​</a></h3><p>删除本地一个或多个镜像。参数说明：</p><ul><li><strong>-f :</strong> 强制删除；</li><li><strong>–no-prune :</strong> 不移除该镜像的过程镜像，默认移除；</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 强制删除本地镜像 guodong/ubuntu:v4。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker rmi -f guodong/ubuntu:v4</span></span></code></pre></div><h3 id="tag" tabindex="-1">tag <a class="header-anchor" href="#tag" aria-label="Permalink to &quot;tag&quot;">​</a></h3><p>标记本地镜像，将其归入某一仓库。</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 将镜像ubuntu:15.10标记为 runoob/ubuntu:v3 镜像。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker tag ubuntu:15.10 runoob/ubuntu:v3</span></span></code></pre></div><h3 id="build" tabindex="-1">build <a class="header-anchor" href="#build" aria-label="Permalink to &quot;build&quot;">​</a></h3><p>用于使用 Dockerfile 创建镜像。参数说明：</p><ul><li><strong>–build-arg=[] :</strong> 设置镜像创建时的变量；</li><li><strong>–cpu-shares :</strong> 设置 cpu 使用权重；</li><li><strong>–cpu-period :</strong> 限制 CPU CFS周期；</li><li><strong>–cpu-quota :</strong> 限制 CPU CFS配额；</li><li><strong>–cpuset-cpus :</strong> 指定使用的CPU id；</li><li><strong>–cpuset-mems :</strong> 指定使用的内存 id；</li><li><strong>–disable-content-trust :</strong> 忽略校验，默认开启；</li><li><strong>-f :</strong> 指定要使用的Dockerfile路径；</li><li><strong>–force-rm :</strong> 设置镜像过程中删除中间容器；</li><li><strong>–isolation :</strong> 使用容器隔离技术；</li><li><strong>–label=[] :</strong> 设置镜像使用的元数据；</li><li><strong>-m :</strong> 设置内存最大值；</li><li><strong>–memory-swap :</strong> 设置Swap的最大值为内存+swap，&quot;-1&quot;表示不限swap；</li><li><strong>–no-cache :</strong> 创建镜像的过程不使用缓存；</li><li><strong>–pull :</strong> 尝试去更新镜像的新版本；</li><li><strong>–quiet, -q :</strong> 安静模式，成功后只输出镜像 ID；</li><li><strong>–rm :</strong> 设置镜像成功后删除中间容器；</li><li><strong>–shm-size :</strong> 设置/dev/shm的大小，默认值是64M；</li><li><strong>–ulimit :</strong> Ulimit配置。</li><li><strong>–squash :</strong> 将 Dockerfile 中所有的操作压缩为一层。</li><li><strong>–tag, -t:</strong> 镜像的名字及标签，通常 name:tag 或者 name 格式；可以在一次构建中为一个镜像设置多个标签。</li><li><strong>–network:</strong> 默认 default。在构建期间设置RUN指令的网络模式</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 使用当前目录的 Dockerfile 创建镜像，标签为 runoob/ubuntu:v1  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker build -t runoob/ubuntu:v1 .   </span></span>
<span class="line"><span style="color:#A6ACCD;"></span></span>
<span class="line"><span style="color:#A6ACCD;"># 使用URL github.com/creack/docker-firefox 的 Dockerfile 创建镜像  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker build github.com/creack/docker-firefox  </span></span>
<span class="line"><span style="color:#A6ACCD;"></span></span>
<span class="line"><span style="color:#A6ACCD;"># 通过 -f Dockerfile文件的位置 创建镜像  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker build -f /path/to/a/Dockerfile .</span></span></code></pre></div><h3 id="history" tabindex="-1">history <a class="header-anchor" href="#history" aria-label="Permalink to &quot;history&quot;">​</a></h3><p>查看指定镜像的创建历史。参数说明：</p><ul><li><strong>-H :</strong> 以可读的格式打印镜像大小和日期，默认为true；</li><li><strong>–no-trunc :</strong> 显示完整的提交记录；</li><li><strong>-q :</strong> 仅列出提交记录ID。</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 查看本地镜像 guodong/ubuntu:v3 的创建历史。  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker history guodong/ubuntu:v3</span></span></code></pre></div><h3 id="save" tabindex="-1">save <a class="header-anchor" href="#save" aria-label="Permalink to &quot;save&quot;">​</a></h3><p>将指定镜像保存成 tar 归档文件。参数说明：</p><ul><li><strong>-o :</strong> 输出到的文件。</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 将镜像 runoob/ubuntu:v3 生成 my_ubuntu_v3.tar 文档  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker save -o my_ubuntu_v3.tar runoob/ubuntu:v3</span></span></code></pre></div><h3 id="load" tabindex="-1">load <a class="header-anchor" href="#load" aria-label="Permalink to &quot;load&quot;">​</a></h3><p>导入使用 <code>docker save</code> 命令导出的镜像。参数说明：</p><ul><li><strong>–input , -i :</strong> 指定导入的文件，代替 STDIN。</li><li><strong>–quiet , -q :</strong> 精简输出信息。</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 导入镜像  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker load --input fedora.tar</span></span></code></pre></div><h3 id="import" tabindex="-1">import <a class="header-anchor" href="#import" aria-label="Permalink to &quot;import&quot;">​</a></h3><p>从归档文件中创建镜像。参数说明：</p><ul><li><strong>-c :</strong> 应用docker 指令创建镜像；</li><li><strong>-m :</strong> 提交时的说明文字；</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 从镜像归档文件my_ubuntu_v3.tar创建镜像，命名为runoob/ubuntu:v4  </span></span>
<span class="line"><span style="color:#A6ACCD;">docker import  my_ubuntu_v3.tar runoob/ubuntu:v4</span></span></code></pre></div><h2 id="实用命令⭐" tabindex="-1">实用命令⭐ <a class="header-anchor" href="#实用命令⭐" aria-label="Permalink to &quot;实用命令⭐&quot;">​</a></h2><p>在平时的工作中，docker 接触得很多，除了经常使用的 docker run ，docker stop 等命令，docker 还有很多十分有用但是却不经常使用的命令，下面就来总结一下：</p><h3 id="_1-docker-top" tabindex="-1">1. docker top <a class="header-anchor" href="#_1-docker-top" aria-label="Permalink to &quot;1. docker top&quot;">​</a></h3><p>这个命令是用来查看一个容器里面的进程信息的，比如你想查看一个 nginx 容器里面有几个 nginx 进程的时候，就可以这么做：</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker top </span><span style="color:#F78C6C;">3b307a09d20d</span></span>
<span class="line"><span style="color:#A6ACCD;">UID      PID    PPID    C    STIME  TTY    TIME       CMD</span></span>
<span class="line"><span style="color:#A6ACCD;">root     </span><span style="color:#F78C6C;">805</span><span style="color:#A6ACCD;">    </span><span style="color:#F78C6C;">787</span><span style="color:#A6ACCD;">     </span><span style="color:#F78C6C;">0</span><span style="color:#A6ACCD;">    Jul13   </span><span style="color:#89DDFF;">?</span><span style="color:#A6ACCD;">   </span><span style="color:#F78C6C;">00</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">00</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">00</span><span style="color:#A6ACCD;">  nginx: master process nginx </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">g daemon off</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">systemd</span><span style="color:#89DDFF;">+</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">941</span><span style="color:#A6ACCD;">     </span><span style="color:#F78C6C;">805</span><span style="color:#A6ACCD;">     </span><span style="color:#F78C6C;">0</span><span style="color:#A6ACCD;">   Jul13    </span><span style="color:#89DDFF;">?</span><span style="color:#A6ACCD;">   </span><span style="color:#F78C6C;">00</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">03</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">18</span><span style="color:#A6ACCD;">  nginx: worker process</span></span></code></pre></div><h3 id="_2-docker-load-docker-save" tabindex="-1">2. docker load &amp;&amp; docker save <a class="header-anchor" href="#_2-docker-load-docker-save" aria-label="Permalink to &quot;2. docker load &amp;&amp; docker save&quot;">​</a></h3><p>我一般使用这两个命令去下载打包 Kubernetes 的镜像，因为你知道的国内的网速并不像国外那么快。</p><p>docker save 可以把一个镜像保存到 tar 文件中，你可以这么做：</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">~</span><span style="color:#A6ACCD;"> docker save registry:</span><span style="color:#F78C6C;">2.7.1</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">registry</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">2.7.1</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">tar</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 同时 docker load 可以把镜像从 tar 文件导入到 docker 中</span></span>
<span class="line"><span style="color:#89DDFF;">~</span><span style="color:#A6ACCD;"> docker load </span><span style="color:#89DDFF;">&lt;</span><span style="color:#A6ACCD;"> registry</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">2.7.1</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">tar</span></span></code></pre></div><h3 id="_3-docker-search" tabindex="-1">3. docker search <a class="header-anchor" href="#_3-docker-search" aria-label="Permalink to &quot;3. docker search&quot;">​</a></h3><p>这个命令可以帮助你在命令行中方便的搜索 DockerHub 中的镜像，比如:</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">~</span><span style="color:#A6ACCD;"> docker search nginx</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.30/202207311625245.png" alt="image-20220731162519059" style="zoom:67%;"><p>当然这个功能在国内可能不会特别好用，因为......</p><h3 id="_4-docker-events" tabindex="-1">4. docker events <a class="header-anchor" href="#_4-docker-events" aria-label="Permalink to &quot;4. docker events&quot;">​</a></h3><p>这命令会卡住</p><p>这个命令可以帮助你实时获取 docker 的各种事件信息，比如创建了一个容器什么的。</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">~</span><span style="color:#A6ACCD;"> docker events</span></span>
<span class="line"><span style="color:#F78C6C;">2020</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">07</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">28T21</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">28</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">46.000403018</span><span style="color:#89DDFF;">+</span><span style="color:#F78C6C;">08</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">00</span><span style="color:#A6ACCD;"> image load sha256:</span><span style="color:#F78C6C;">432bf69f0427b52cad10897342eaf23521b7d973566354118e9a59c4d31b5fae</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">name</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">sha256:</span><span style="color:#F78C6C;">432bf69f0427b52cad10897342eaf23521b7d973566354118e9a59c4d31b5fae</span><span style="color:#89DDFF;">)</span></span></code></pre></div><h3 id="_5-docker-update" tabindex="-1">5. docker update <a class="header-anchor" href="#_5-docker-update" aria-label="Permalink to &quot;5. docker update&quot;">​</a></h3><p>当你 docker run 了之后却发现里面有一些参数并不是你想要的状态比如你设置的 nginx 容器 cpu 或者内存太小，这个时候你就可以使用 docker update 去修改这些参数。</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">~</span><span style="color:#A6ACCD;"> docker update nginx </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">cpus </span><span style="color:#F78C6C;">2</span></span></code></pre></div><h3 id="_6-docker-history" tabindex="-1">6. docker history <a class="header-anchor" href="#_6-docker-history" aria-label="Permalink to &quot;6. docker history&quot;">​</a></h3><p>当你修改了一个镜像，但是忘记了每一层的修改命令，或者你想查看一个镜像是怎么构建的时候就可以使用这个命令，比如：</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">~</span><span style="color:#A6ACCD;"> docker history  traefik:v2</span><span style="color:#F78C6C;">.1.6</span></span>
<span class="line"><span style="color:#A6ACCD;">IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT</span></span>
<span class="line"><span style="color:#F78C6C;">5212a87ddaba</span><span style="color:#A6ACCD;">        </span><span style="color:#F78C6C;">5</span><span style="color:#A6ACCD;"> months ago        </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">sh </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">c </span><span style="color:#89DDFF;">#(</span><span style="color:#A6ACCD;">nop</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">  LABEL org</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">opencontainers</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">…   </span><span style="color:#F78C6C;">0B</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#A6ACCD;">missing</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">           </span><span style="color:#F78C6C;">5</span><span style="color:#A6ACCD;"> months ago        </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">sh </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">c </span><span style="color:#89DDFF;">#(</span><span style="color:#A6ACCD;">nop</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">  CMD </span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">traefik</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;">              </span><span style="color:#F78C6C;">0B</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#A6ACCD;">missing</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">           </span><span style="color:#F78C6C;">5</span><span style="color:#A6ACCD;"> months ago        </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">sh </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">c </span><span style="color:#89DDFF;">#(</span><span style="color:#A6ACCD;">nop</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">  ENTRYPOINT </span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">/entrypoint.…   0B</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#A6ACCD;">missing</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">           </span><span style="color:#F78C6C;">5</span><span style="color:#A6ACCD;"> months ago        </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">sh </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">c </span><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;">(nop)  EXPOSE </span><span style="color:#F78C6C;">80</span><span style="color:#A6ACCD;">                    </span><span style="color:#F78C6C;">0B</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#A6ACCD;">missing</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">           </span><span style="color:#F78C6C;">5</span><span style="color:#A6ACCD;"> months ago        </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">sh </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">c </span><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;">(nop) COPY file:</span><span style="color:#F78C6C;">59a219a1fb7a9dc8</span><span style="color:#A6ACCD;">…   </span><span style="color:#F78C6C;">419B</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#A6ACCD;">missing</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">           </span><span style="color:#F78C6C;">5</span><span style="color:#A6ACCD;"> months ago        </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">sh </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">c set </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">ex</span><span style="color:#89DDFF;">;</span><span style="color:#A6ACCD;">  apkArch</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">$(apk --print-…   52.9MB</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#A6ACCD;">missing</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">           </span><span style="color:#F78C6C;">5</span><span style="color:#A6ACCD;"> months ago        </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">sh </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">c apk </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">no</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">cache add ca</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">certificate…   </span><span style="color:#F78C6C;">1.85MB</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#A6ACCD;">missing</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">           </span><span style="color:#F78C6C;">6</span><span style="color:#A6ACCD;"> months ago        </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">sh </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">c </span><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;">(nop)  CMD [</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">/bin/sh</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">]</span><span style="color:#A6ACCD;">              </span><span style="color:#F78C6C;">0B</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#A6ACCD;">missing</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">           </span><span style="color:#F78C6C;">6</span><span style="color:#A6ACCD;"> months ago        </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">sh </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">c </span><span style="color:#89DDFF;">#(</span><span style="color:#A6ACCD;">nop</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;"> ADD file:a1906f14a4e217a49…   </span><span style="color:#F78C6C;">4.81MB</span></span></code></pre></div><h3 id="_7-docker-wait" tabindex="-1">7. docker wait <a class="header-anchor" href="#_7-docker-wait" aria-label="Permalink to &quot;7. docker wait&quot;">​</a></h3><p>这个命令可以查看容器的退出状态，比如：</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">~</span><span style="color:#A6ACCD;"> docker wait </span><span style="color:#F78C6C;">7f7f0522a7d0</span></span>
<span class="line"><span style="color:#F78C6C;">0</span></span></code></pre></div><p>这样你就可以知道这个容器是正常退出的还是异常退出的了。</p><h3 id="_8-docker-pause-docker-unpause" tabindex="-1">8. docker pause &amp;&amp; docker unpause <a class="header-anchor" href="#_8-docker-pause-docker-unpause" aria-label="Permalink to &quot;8. docker pause &amp;&amp; docker unpause&quot;">​</a></h3><p>当你运行了一个容器但是想要暂停它运行的时候，你就可以使用这个命令。</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">~</span><span style="color:#A6ACCD;"> docker pause </span><span style="color:#F78C6C;">7f7f0522a7d0</span></span></code></pre></div><h3 id="_9-docker-diff" tabindex="-1">9. docker diff <a class="header-anchor" href="#_9-docker-diff" aria-label="Permalink to &quot;9. docker diff&quot;">​</a></h3><p>当你运行了一个容器，但是你不知道容器里修改了哪一些文件的时候可以使用这个命令，比如：</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight has-diff"><code><span class="line"><span style="color:#A6ACCD;">docker diff </span><span style="color:#F78C6C;">38c59255bf6e</span></span>
<span class="line"><span style="color:#A6ACCD;">C </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span></span>
<span class="line"><span style="color:#A6ACCD;">A </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">localtime</span></span>
<span class="line"><span style="color:#A6ACCD;">C </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span></span>
<span class="line"><span style="color:#A6ACCD;">C </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span></span>
<span class="line"><span style="color:#A6ACCD;">A </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">registry</span></span></code></pre></div><h3 id="_10-docker-stats" tabindex="-1">10. docker stats <a class="header-anchor" href="#_10-docker-stats" aria-label="Permalink to &quot;10. docker stats&quot;">​</a></h3><p>这个是 docker 内置的监控命令，当你想要查看当前主机下所有容器占用内存和 cpu 的情况的时候就可以使用这个命令。</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker stats</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.30/202207311622672.png" alt="image-20220731162246516" style="zoom:67%;"><h1 id="日志清理" tabindex="-1">日志清理 <a class="header-anchor" href="#日志清理" aria-label="Permalink to &quot;日志清理&quot;">​</a></h1><h2 id="日志查看" tabindex="-1">日志查看 <a class="header-anchor" href="#日志查看" aria-label="Permalink to &quot;日志查看&quot;">​</a></h2><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#82AAFF;">cd</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/var/lib/docker/containers/</span></span></code></pre></div><p>在这里都是以容器ID开头的容器名，后面用容器ID+通配符*进入容器文件内部，然后删除*-json.log文件即可</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">du</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-sh</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/var/lib/docker/</span><span style="color:#A6ACCD;">*</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> </span><span style="color:#FFCB6B;">sort</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-nr</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.12.30/202210242018341.png" alt="image-20221024201846255" style="zoom:80%;"><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">du</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-sh</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/var/lib/docker/containers/</span><span style="color:#A6ACCD;">*</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> </span><span style="color:#FFCB6B;">sort</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-nr</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.12.30/202210242013909.png" alt="image-20221024201347792" style="zoom:80%;"><h2 id="日志清理方案" tabindex="-1">日志清理方案 <a class="header-anchor" href="#日志清理方案" aria-label="Permalink to &quot;日志清理方案&quot;">​</a></h2><ul><li><strong>方案一</strong>：手动清理日志文件，可解燃眉之急，治标不治本。</li><li><strong>方案二</strong>：脚本定期清理日志文件，缺点是日志文件全丢了，无法追溯。</li><li><strong>方案三</strong>：限制所有容器的日志文件大小，治本，缺点是需要重新创建容器和启动 docker 镜像。</li></ul><h3 id="方案一-手动清理方案" tabindex="-1">方案一：手动清理方案 <a class="header-anchor" href="#方案一-手动清理方案" aria-label="Permalink to &quot;方案一：手动清理方案&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">cat </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">dev</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">null </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">docker</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">containers</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">容器id</span><span style="color:#89DDFF;">+*/</span><span style="color:#A6ACCD;">容器id</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">json</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">log</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">cat </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">dev</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">null </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">docker</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">containers</span><span style="color:#89DDFF;">/</span><span style="color:#F78C6C;">142d015f36cc</span><span style="color:#89DDFF;">*/</span><span style="color:#F78C6C;">142d015f36cc</span><span style="color:#89DDFF;">*-</span><span style="color:#A6ACCD;">json</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">log</span></span></code></pre></div><p>注意：这里没有使用 <code>rm</code> 方式来删除文件。使用 <code>rm -rf</code> 方式删除日志后，通过 <code>df -h</code> 会发现磁盘空间并没有释放。原因是在 Linux 或者 Unix 系统中，通过 <code>rm -rf</code> 或者文件管理器删除文件，将会从文件系统的目录结构上解除链接（unlink）。如果文件是被打开的（有一个进程正在使用），那么进程将仍然可以读取该文件，磁盘空间也一直被占用。正确姿势是 cat /dev/null &gt; *-json.log，当然也可以通过 rm -rf 删除后重启 docker。</p><h3 id="方案二-脚本定期清理" tabindex="-1">方案二：脚本定期清理 <a class="header-anchor" href="#方案二-脚本定期清理" aria-label="Permalink to &quot;方案二：脚本定期清理&quot;">​</a></h3><p>提供一个清理脚本。</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;">#!/bin/sh </span></span>
<span class="line"></span>
<span class="line"><span style="color:#82AAFF;">echo</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">======== start clean docker containers logs ========</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">logs</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">$(</span><span style="color:#FFCB6B;">find</span><span style="color:#C3E88D;"> /var/lib/docker/containers/ -name </span><span style="color:#A6ACCD;">*</span><span style="color:#C3E88D;">-json.log</span><span style="color:#89DDFF;">)</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">for</span><span style="color:#A6ACCD;"> log </span><span style="color:#89DDFF;font-style:italic;">in</span><span style="color:#A6ACCD;"> $logs  </span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#89DDFF;font-style:italic;">do</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#82AAFF;">echo</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">clean logs : </span><span style="color:#A6ACCD;">$log</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"><span style="color:#A6ACCD;">                </span><span style="color:#FFCB6B;">cat</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/dev/null</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> $log  </span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#89DDFF;font-style:italic;">done</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"></span>
<span class="line"><span style="color:#82AAFF;">echo</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">======== end clean docker containers logs ========</span><span style="color:#89DDFF;">&quot;</span></span></code></pre></div><p>执行脚本的命令。</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">sh</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">clean_docker_log.sh</span></span></code></pre></div><p>大家可以把执行脚本的命令加到 Linux 的<code>定时任务</code>中就可以了，这里不做展开。</p><p>下面要说的是我目前使用的方案。</p><h3 id="方案三-限制-docker-容器日志大小" tabindex="-1">方案三：限制 Docker 容器日志大小 <a class="header-anchor" href="#方案三-限制-docker-容器日志大小" aria-label="Permalink to &quot;方案三：限制 Docker 容器日志大小&quot;">​</a></h3><p>新建 /etc/docker/daemon.json，若有就不用新建了。</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">vim</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/etc/docker/daemon.json</span></span></code></pre></div><p>配置内容如下：</p><div class="language-json"><button title="Copy Code" class="copy"></button><span class="lang">json</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C792EA;">log-driver</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">json-file</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C792EA;">log-opts</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span><span style="color:#89DDFF;">&quot;</span><span style="color:#FFCB6B;">max-size</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">500m</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#FFCB6B;">max-file</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">:</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">3</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#89DDFF;">}</span></span></code></pre></div><p>max-size=500m，表示容器的日志文件大小上限是 500M。max-file=3，表示容器有三个日志，第一个满了 500M 之后就写第二个，第二个满了 500M 就写第三个，如果第三个满了，就清空第一个日志文件，重新写第一个日志文件。如下图所示：</p><p><img src="https://mmbiz.qpic.cn/mmbiz_png/SfAHMuUxqJ1keHzuw775yZPDECYhgVoZG4jJUo6OMLVxrkPicJnD9ynMpnxTbFRk7cGlpkYtVvQEFqw1xKebGGw/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片">写了 3 个日志文件，最大不超过 500M</p><p>改完之后需要重启 docker 守护进程。</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">systemctl daemon-reload</span></span>
<span class="line"><span style="color:#A6ACCD;">systemctl restart docker</span></span></code></pre></div><p>另外这种方式只对新建的容器有效，之前的容器不生效，所以我又把之前的 Logstash 容器删除了，然后重新启动了一个 Logstash 容器。</p><h1 id="本地镜像发布到阿里云" tabindex="-1">本地镜像发布到阿里云 <a class="header-anchor" href="#本地镜像发布到阿里云" aria-label="Permalink to &quot;本地镜像发布到阿里云&quot;">​</a></h1><h2 id="创建本地镜像" tabindex="-1">创建本地镜像 <a class="header-anchor" href="#创建本地镜像" aria-label="Permalink to &quot;创建本地镜像&quot;">​</a></h2><p>进入ubuntu容器</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it ubuntu bash</span></span></code></pre></div><p>安装vim编辑器</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">apt-get update</span></span>
<span class="line"><span style="color:#A6ACCD;">apt-get install vim</span></span></code></pre></div><p>创建文件</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">vi test.txt</span></span></code></pre></div><p><strong>导出容器并导入成本地镜像</strong></p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker export </span><span style="color:#F78C6C;">84b15e00abbc</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> ubuntuPro</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">tar</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">cat ubuntuPro</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">tar </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> docker import </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> renshuo</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">ubantupro:</span><span style="color:#F78C6C;">1.0</span></span></code></pre></div><p>再进行查看</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker images</span></span></code></pre></div><h2 id="配置阿里云" tabindex="-1">配置阿里云 <a class="header-anchor" href="#配置阿里云" aria-label="Permalink to &quot;配置阿里云&quot;">​</a></h2><p>创建命名空间</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220213181834112.png" alt="image-20220213181834112" style="zoom:67%;"><p>创建镜像仓库</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220207185258523.png" alt="image-20220207185258523" style="zoom:50%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220207185310985.png" alt="image-20220207185310985" style="zoom:50%;"><p>点击管理</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220207185416401.png" alt="image-20220207185416401" style="zoom:67%;"><p>安装图示操作即可</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220207185503051.png" alt="image-20220207185503051" style="zoom:67%;"><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker login --username=任硕8673 registry.cn-hangzhou.aliyuncs.com</span></span></code></pre></div><p>密码就是登录密码，315217ren</p><p>推送镜像</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker tag bc3a8d5b4d88 registry.cn-hangzhou.aliyuncs.com/myubantu1/myubuntu1:2.0</span></span></code></pre></div><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker push registry.cn-hangzhou.aliyuncs.com/myubantu1/myubuntu1:2.0</span></span></code></pre></div><p>拉取镜像</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker pull registry.cn-hangzhou.aliyuncs.com/myubantu1/myubuntu1:2.0</span></span></code></pre></div><p>使用</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker images</span></span>
<span class="line"><span style="color:#A6ACCD;">docker run -it  bc3a8d5b4d88  bash</span></span></code></pre></div><h1 id="数据卷" tabindex="-1">数据卷 <a class="header-anchor" href="#数据卷" aria-label="Permalink to &quot;数据卷&quot;">​</a></h1><blockquote><p>就是实现不同容器，<strong>容器与外部系统间文件交换</strong>，信息传递和查看。在之前的nginx案例中，修改nginx的html页面时，需要进入nginx内部。并且因为没有编辑器，修改文件也很麻烦。这就是因为<strong>容器与数据（容器内文件）耦合带来的后果</strong>。</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011148839.png" alt="image-20210731172440275" style="zoom:67%;"><p>要解决这个问题，必须将数据与容器解耦，这就要用到数据卷了。</p><blockquote><ol><li>docker修改，主机同步获得</li><li>主机修改，docker同步获得</li><li>docker容器stop，主机修改，docker容器重启看数据是否同步</li></ol></blockquote><h2 id="什么是数据卷" tabindex="-1">什么是数据卷 <a class="header-anchor" href="#什么是数据卷" aria-label="Permalink to &quot;什么是数据卷&quot;">​</a></h2><blockquote><p>**数据卷（volume）**是一个虚拟目录，指向宿主机文件系统中的某个目录。</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011149062.png" alt="image-20210731173541846" style="zoom:67%;"><blockquote><p>一旦完成数据卷挂载，对容器的一切操作都会作用在数据卷对应的宿主机目录了。这样，我们操作宿主机的/var/lib/docker/volumes/html目录，就等于操作容器内的/usr/share/nginx/html目录了</p></blockquote><p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202306061946128.png" alt="image-20230606194623001"></p><h2 id="基本语法" tabindex="-1">基本语法 <a class="header-anchor" href="#基本语法" aria-label="Permalink to &quot;基本语法&quot;">​</a></h2><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 数据卷操作的基本语法</span></span>
<span class="line"><span style="color:#A6ACCD;">docker volume </span><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">COMMAND</span><span style="color:#89DDFF;">]</span></span></code></pre></div><p>docker volume命令是数据卷操作，根据命令后跟随的command来确定下一步的操作：</p><blockquote><ul><li>create 创建一个volume</li><li>inspect 显示一个或多个volume的信息</li><li>ls 列出所有的volume</li><li>prune 删除未使用的volume</li><li>rm 删除一个或多个指定的volume</li></ul></blockquote><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 创建数据卷</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">volume</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">create</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">html</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 查看所有数据</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">volume</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">ls</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 查看数据卷详细信息卷</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">volume</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">inspect</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">html</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 删除没使用的数据卷</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">volume</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">prune</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 删除指定数据卷</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">volume</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">rm</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">html</span></span></code></pre></div><h2 id="nginx数据卷挂载" tabindex="-1">Nginx数据卷挂载 <a class="header-anchor" href="#nginx数据卷挂载" aria-label="Permalink to &quot;Nginx数据卷挂载&quot;">​</a></h2><blockquote><ul><li>目录必须是绝对路径</li><li><strong>如果目录不存在，会自动创建</strong></li><li><strong>可以挂载多个数据卷</strong></li><li>语法：-v 主机目录：容器目录 镜像名</li></ul></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202306061645316.png" alt="image-20230606164548187" style="zoom:80%;"><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-it</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--privileged=true</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-v</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/宿主机绝对路径目录:/容器内目录</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">镜像名</span></span></code></pre></div><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-it</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--name</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx1</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">--privileged=true \</span></span>
<span class="line"><span style="color:#A6ACCD;">-p </span><span style="color:#F78C6C;">80</span><span style="color:#C3E88D;">:80</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/root/html:/usr/share/nginx/html</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-d </span><span style="color:#C3E88D;">nginx</span></span></code></pre></div><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 在宿主机进行操作</span></span>
<span class="line"><span style="color:#82AAFF;">cd</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/root/html</span></span>
<span class="line"><span style="color:#FFCB6B;">touch</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">index.html</span></span>
<span class="line"><span style="color:#82AAFF;">echo</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">hello,world</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">index.html</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202306061701727.png" alt="image-20230606170159603" style="zoom:80%;"><h2 id="mysql数据卷挂载" tabindex="-1">MySQL数据卷挂载 <a class="header-anchor" href="#mysql数据卷挂载" aria-label="Permalink to &quot;MySQL数据卷挂载&quot;">​</a></h2><blockquote><p>一个容器可以挂载多个目录，\表示没写完，回车后继续写</p></blockquote><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># /etc/mysql/conf.d最后会将文件内容合并到my.cnf中</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-d</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">3309</span><span style="color:#C3E88D;">:3306</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--privileged=true</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/log:/var/log/mysql</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/data:/var/lib/mysql</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/conf:/etc/mysql/conf.d</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-e </span><span style="color:#C3E88D;">MYSQL_ROOT_PASSWORD=</span><span style="color:#F78C6C;">123456</span><span style="color:#A6ACCD;">  \</span></span>
<span class="line"><span style="color:#A6ACCD;">--name </span><span style="color:#C3E88D;">mysql5.7.25</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql:5.7.25</span></span></code></pre></div><blockquote><p>修改权限，让外部能够连接</p></blockquote><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">exec</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-it</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mysql5.7.25</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">bash</span></span>
<span class="line"><span style="color:#FFCB6B;">mysql</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-uroot</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p123456</span></span>
<span class="line"><span style="color:#FFCB6B;">use</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mysql</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#FFCB6B;">grant</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">all</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">on</span><span style="color:#A6ACCD;"> </span><span style="color:#A6ACCD;">*</span><span style="color:#C3E88D;">.</span><span style="color:#A6ACCD;">*</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">to</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">root</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">@</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">%</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#FFCB6B;">flush</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">privileges</span><span style="color:#89DDFF;">;</span></span></code></pre></div><blockquote><p>①数据卷挂载耦合度低，由docker来管理目录，但是目录较深，不好找</p><p>②目录挂载耦合度高，需要我们自己管理目录，不过目录容易寻找查看</p></blockquote><h1 id="自定义镜像" tabindex="-1">自定义镜像 <a class="header-anchor" href="#自定义镜像" aria-label="Permalink to &quot;自定义镜像&quot;">​</a></h1><p>常见的镜像在DockerHub就能找到，但是我们自己写的项目就必须自己构建镜像了。</p><p>而要自定义镜像，就必须先了解镜像的结构才行。</p><h2 id="镜像结构" tabindex="-1">镜像结构 <a class="header-anchor" href="#镜像结构" aria-label="Permalink to &quot;镜像结构&quot;">​</a></h2><p>镜像是将应用程序及其需要的系统函数库、环境、配置、依赖打包而成。</p><p>我们以MySQL为例，来看看镜像的组成结构：</p><p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202306061953405.png" alt="image-20210731175806273"></p><blockquote><p>简单来说，镜像就是在系统函数库、运行环境基础上，添加应用程序文件、配置文件、依赖文件等组合，然后编写好启动脚本打包在一起形成的文件。要构建镜像，其实就是实现上述打包的过程。</p></blockquote><h2 id="dockerfile语法" tabindex="-1">Dockerfile语法 <a class="header-anchor" href="#dockerfile语法" aria-label="Permalink to &quot;Dockerfile语法&quot;">​</a></h2><blockquote><p>构建自定义的镜像时，并不需要一个个文件去拷贝，打包。我们只需要告诉Docker，我们的镜像的组成，需要哪些BaseImage、需要拷贝什么文件、需要安装什么依赖、启动脚本是什么，将来Docker会帮助我们构建镜像。而描述上述信息的文件就是Dockerfile文件。</p></blockquote><blockquote><p><strong>Dockerfile</strong>就是一个文本文件，其中包含一个个的<strong>指令(Instruction)</strong>，用指令来说明要执行什么操作来构建镜像。每一个指令都会形成一层Layer。</p></blockquote><p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202306061953388.png" alt="image-20210731180321133"></p><blockquote><p>更新详细语法说明，请参考官网文档： <a href="https://docs.docker.com/engine/reference/builder" target="_blank" rel="noreferrer">https://docs.docker.com/engine/reference/builder</a></p></blockquote><h2 id="构建java项目" tabindex="-1">构建Java项目 <a class="header-anchor" href="#构建java项目" aria-label="Permalink to &quot;构建Java项目&quot;">​</a></h2><h3 id="基于ubuntu构建java项目" tabindex="-1">基于Ubuntu构建Java项目 <a class="header-anchor" href="#基于ubuntu构建java项目" aria-label="Permalink to &quot;基于Ubuntu构建Java项目&quot;">​</a></h3><p>需求：基于Ubuntu镜像构建一个新镜像，运行一个java项目</p><p>步骤1：新建一个空文件夹docker-demo</p><p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202306061953397.png" alt="image-20210801101207444"></p><p>步骤2：拷贝课前资料中的docker-demo.jar文件到docker-demo这个目录</p><p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202306061953399.png" alt="image-20210801101314816"></p><p>步骤3：拷贝课前资料中的jdk8.tar.gz文件到docker-demo这个目录</p><p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202306061953401.png" alt="image-20210801101410200"></p><p>步骤4：拷贝课前资料提供的Dockerfile到docker-demo这个目录</p><p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.3.30/202306061953429.png" alt="image-20210801101455590"></p><p>其中的内容如下：</p><div class="language-dockerfile"><button title="Copy Code" class="copy"></button><span class="lang">dockerfile</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 指定基础镜像</span></span>
<span class="line"><span style="color:#F78C6C;">FROM</span><span style="color:#A6ACCD;"> ubuntu:16.04</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 配置环境变量，JDK的安装目录</span></span>
<span class="line"><span style="color:#F78C6C;">ENV</span><span style="color:#A6ACCD;"> JAVA_DIR=/usr/local</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 拷贝jdk和java项目的包</span></span>
<span class="line"><span style="color:#F78C6C;">COPY</span><span style="color:#A6ACCD;"> ./jdk8.tar.gz $JAVA_DIR/</span></span>
<span class="line"><span style="color:#F78C6C;">COPY</span><span style="color:#A6ACCD;"> ./docker-demo.jar /tmp/app.jar</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 安装JDK</span></span>
<span class="line"><span style="color:#F78C6C;">RUN</span><span style="color:#A6ACCD;"> cd $JAVA_DIR \</span></span>
<span class="line"><span style="color:#A6ACCD;"> &amp;&amp; tar -xf ./jdk8.tar.gz \</span></span>
<span class="line"><span style="color:#A6ACCD;"> &amp;&amp; mv ./jdk1.8.0_144 ./java8</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 配置环境变量</span></span>
<span class="line"><span style="color:#F78C6C;">ENV</span><span style="color:#A6ACCD;"> JAVA_HOME=$JAVA_DIR/java8</span></span>
<span class="line"><span style="color:#F78C6C;">ENV</span><span style="color:#A6ACCD;"> PATH=$PATH:$JAVA_HOME/bin</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 暴露端口</span></span>
<span class="line"><span style="color:#F78C6C;">EXPOSE</span><span style="color:#A6ACCD;"> 8090</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 入口，java项目的启动命令</span></span>
<span class="line"><span style="color:#F78C6C;">ENTRYPOINT</span><span style="color:#A6ACCD;"> java -jar /tmp/app.jar</span></span></code></pre></div><p>步骤5：进入docker-demo</p><p>将准备好的docker-demo上传到虚拟机任意目录，然后进入docker-demo目录下</p><p>步骤6：运行命令：</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">build</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-t</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">javaweb:1.0</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">.</span></span></code></pre></div><p>最后访问 <a href="http://192.168.150.101:8090/hello/count%EF%BC%8C%E5%85%B6%E4%B8%AD%E7%9A%84ip%E6%94%B9%E6%88%90%E4%BD%A0%E7%9A%84%E8%99%9A%E6%8B%9F%E6%9C%BAip" target="_blank" rel="noreferrer">http://192.168.150.101:8090/hello/count，其中的ip改成你的虚拟机ip</a></p><h3 id="基于java8构建java项目" tabindex="-1">基于java8构建Java项目 <a class="header-anchor" href="#基于java8构建java项目" aria-label="Permalink to &quot;基于java8构建Java项目&quot;">​</a></h3><p>虽然我们可以基于Ubuntu基础镜像，添加任意自己需要的安装包，构建镜像，但是却比较麻烦。所以大多数情况下，我们都可以在一些安装了部分软件的基础镜像上做改造。</p><p>例如，构建java项目的镜像，可以在已经准备了JDK的基础镜像基础上构建。</p><p>需求：基于java:8-alpine镜像，将一个Java项目构建为镜像</p><p>实现思路如下：</p><ul><li><p>① 新建一个空的目录，然后在目录中新建一个文件，命名为Dockerfile</p></li><li><p>② 拷贝课前资料提供的docker-demo.jar到这个目录中</p></li><li><p>③ 编写Dockerfile文件：</p><ul><li><p>a ）基于java:8-alpine作为基础镜像</p></li><li><p>b ）将app.jar拷贝到镜像中</p></li><li><p>c ）暴露端口</p></li><li><p>d ）编写入口ENTRYPOINT</p><p>内容如下：</p><div class="language-dockerfile"><button title="Copy Code" class="copy"></button><span class="lang">dockerfile</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F78C6C;">FROM</span><span style="color:#A6ACCD;"> java:8-alpine</span></span>
<span class="line"><span style="color:#F78C6C;">COPY</span><span style="color:#A6ACCD;"> ./app.jar /tmp/app.jar</span></span>
<span class="line"><span style="color:#F78C6C;">EXPOSE</span><span style="color:#A6ACCD;"> 8090</span></span>
<span class="line"><span style="color:#F78C6C;">ENTRYPOINT</span><span style="color:#A6ACCD;"> java -jar /tmp/app.jar</span></span></code></pre></div></li></ul></li><li><p>④ 使用docker build命令构建镜像</p></li><li><p>⑤ 使用docker run创建容器并运行</p></li></ul><h1 id="应用部署⭐" tabindex="-1">应用部署⭐ <a class="header-anchor" href="#应用部署⭐" aria-label="Permalink to &quot;应用部署⭐&quot;">​</a></h1><h2 id="总体步骤" tabindex="-1">总体步骤 <a class="header-anchor" href="#总体步骤" aria-label="Permalink to &quot;总体步骤&quot;">​</a></h2><ol><li>搜索镜像</li><li>拉取镜像</li><li>查看镜像</li><li>启动镜像-----注意服务端口映射，第一个端口是外部端口，第二个端口是docker端口，访问时用的是外部端口</li><li>停止容器</li><li>移除容器</li></ol><h2 id="部署mysql" tabindex="-1">部署MySQL <a class="header-anchor" href="#部署mysql" aria-label="Permalink to &quot;部署MySQL&quot;">​</a></h2><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005130553003.png" alt="image-20211005130553003" style="zoom:67%;"><h3 id="问题" tabindex="-1">问题 <a class="header-anchor" href="#问题" aria-label="Permalink to &quot;问题&quot;">​</a></h3><ul><li>插入中文数据试试，为什么报错?因为docker上默认字符集编码隐患</li><li>删除容器后，里面的mysql数据如何办？容器实例一删除，你还有什么？删容器到跑路。。。。。？</li></ul><h3 id="简单版" tabindex="-1">简单版 <a class="header-anchor" href="#简单版" aria-label="Permalink to &quot;简单版&quot;">​</a></h3><p>1、拉取和查看mysql</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker pull mysql:</span><span style="color:#F78C6C;">5.7</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker images</span></span></code></pre></div><p>2、启动mysql：注意：第一个ip3308是对外暴露的ip，第二个ip3306是docker内部的mysql的ip，外部要想访问，则需要访问3308端口。同时注意，mysql默认3306端口，直接修改会导致连接不上去</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">3308</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">3306</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">e MYSQL_ROOT_PASSWORD</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">123456</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d mysql:</span><span style="color:#F78C6C;">5.7</span></span></code></pre></div><p>3、启动和进入容器</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker ps</span></span>
<span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it 容器ID </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span>
<span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it </span><span style="color:#F78C6C;">662ea6ae16e7</span><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456</span></span></code></pre></div><p>4、创建数据库插入数据</p><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">create database mydb01;</span></span>
<span class="line"><span style="color:#A6ACCD;">use mydb01;</span></span>
<span class="line"><span style="color:#A6ACCD;">CREATE TABLE IF NOT EXISTS author(</span></span>
<span class="line"><span style="color:#A6ACCD;">	id INT,</span></span>
<span class="line"><span style="color:#A6ACCD;">	name VARCHAR(20),</span></span>
<span class="line"><span style="color:#A6ACCD;">	country VARCHAR(20)</span></span>
<span class="line"><span style="color:#A6ACCD;">);</span></span>
<span class="line"><span style="color:#A6ACCD;"># 插入表内容</span></span>
<span class="line"><span style="color:#A6ACCD;">INSERT INTO author VALUES(1,&#39;renshuo&#39;,&#39;zhonguo&#39;);</span></span></code></pre></div><p>插入中文出现问题</p><p>查看字符编码，发现不是utf-8，需要进行修改，这就需要用实用版了</p><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show variables like &#39;character%&#39;;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220208123136189.png" alt="image-20220208123136189" style="zoom:67%;"><h3 id="实用版" tabindex="-1">实用版 <a class="header-anchor" href="#实用版" aria-label="Permalink to &quot;实用版&quot;">​</a></h3><p>注意：docker安装完MySQL并run出容器后，建议请先修改完字符集编码后再新建mysql库-表-插数据</p><ol><li>搜索mysql镜像</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">search</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mysql</span></span></code></pre></div><ol start="2"><li>拉取mysql镜像</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">pull</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mysql:5.7</span></span></code></pre></div><ol start="3"><li>创建容器，设置端口映射、目录映射</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-d</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">3309</span><span style="color:#C3E88D;">:3306</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--privileged=true</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/log:/var/log/mysql</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/data:/var/lib/mysql</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/mysql/conf:/etc/mysql/conf.d</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-e </span><span style="color:#C3E88D;">MYSQL_ROOT_PASSWORD=</span><span style="color:#F78C6C;">123456</span><span style="color:#A6ACCD;">  \</span></span>
<span class="line"><span style="color:#A6ACCD;">--name </span><span style="color:#C3E88D;">mysql5.7</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql:5.7</span></span></code></pre></div><ul><li>参数说明： <ul><li><strong>-p 3309:3306</strong>：将容器的 3306 端口映射到宿主机的 3309 端口。</li><li><strong>-v $PWD/conf:/etc/mysql/conf.d</strong>：将主机当前目录下的 conf/my.cnf 挂载到容器的 /etc/mysql/my.cnf。配置目录</li><li><strong>-v /DockerData/mysql/log</strong>：将主机当前目录下的 logs 目录挂载到容器的 /logs。日志目录</li><li><strong>-v /DockerData/mysql/data</strong> ：将主机当前目录下的data目录挂载到容器的 /var/lib/mysql，数据目录</li><li>**-e MYSQL_ROOT_PASSWORD=123456：**初始化 root 用户的密码。</li></ul></li></ul><p><strong>改成中文</strong></p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">cd /DockerData/mysql/conf</span></span>
<span class="line"><span style="color:#A6ACCD;">vim my.cnf</span></span></code></pre></div><p>编辑my.cnf</p><div class="language-ini"><button title="Copy Code" class="copy"></button><span class="lang">ini</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">[client]</span></span>
<span class="line"><span style="color:#F07178;">default_character_set</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">utf8</span></span>
<span class="line"><span style="color:#89DDFF;">[mysqld]</span></span>
<span class="line"><span style="color:#F07178;">collation_server</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> utf8_general_ci</span></span>
<span class="line"><span style="color:#F07178;">character_set_server</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> utf8</span></span></code></pre></div><p>重启mysql5.7服务</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker restart mysql5.7</span></span></code></pre></div><p>查看编码(修改成功)</p><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show variables like &#39;character%&#39;;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220208130605973.png" alt="image-20220208130605973" style="zoom:67%;"><ol start="4"><li>进入容器，操作mysql</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">exec</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-it</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mysql5.7</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/bin/bash</span></span>
<span class="line"><span style="color:#FFCB6B;">mysql</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-uroot</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p123456</span></span></code></pre></div><ol start="5"><li>使用外部机器连接容器中的mysql</li></ol><p>输入ifconfig -a，查看本机ip，会出现很多ip，只需看到如下ens33对应第二行的innet 192.168.220.123就是本机ip地址。</p><p>注意要关闭linux防火墙：永久关闭防火墙：<strong>systemctl disable firewalld</strong></p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005133221984.png" alt="image-20211005133221984" style="zoom:67%;"><p>在外面创建表并添加数据后，可以docker在内部查看。同样，在内部创建也能被外部查看修改。</p><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">create database mydb01;</span></span>
<span class="line"><span style="color:#A6ACCD;">use mydb01;</span></span>
<span class="line"><span style="color:#A6ACCD;">CREATE TABLE IF NOT EXISTS author(</span></span>
<span class="line"><span style="color:#A6ACCD;">	id INT,</span></span>
<span class="line"><span style="color:#A6ACCD;">	name VARCHAR(20),</span></span>
<span class="line"><span style="color:#A6ACCD;">	country VARCHAR(20)</span></span>
<span class="line"><span style="color:#A6ACCD;">);</span></span>
<span class="line"><span style="color:#A6ACCD;"># 插入表内容</span></span>
<span class="line"><span style="color:#A6ACCD;">INSERT INTO author VALUES(1,&#39;renshuo&#39;,&#39;zhonguo&#39;);</span></span>
<span class="line"><span style="color:#A6ACCD;">INSERT INTO author VALUES(2,&#39;任硕&#39;,&#39;中国&#39;);</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220208130814258.png" alt="image-20220208130814258" style="zoom:67%;"><p>假如将当前容器实例删除，再重新来一次，之前建的数据库还有吗？</p><p>1、删除当前mysql容器</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker rm </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f </span><span style="color:#F78C6C;">37f8aee444dd</span></span></code></pre></div><p>2、再次创建启动容器</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">3309</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">3306</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">privileged</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">true </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">log:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">log</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">conf:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">conf</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">e MYSQL_ROOT_PASSWORD</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">123456</span><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name mysql5</span><span style="color:#F78C6C;">.7</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">5.7</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it mysql5</span><span style="color:#F78C6C;">.7</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456</span></span></code></pre></div><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">-- 进行查询，数据依旧存在</span></span>
<span class="line"><span style="color:#A6ACCD;">use mydb01;</span></span>
<span class="line"><span style="color:#A6ACCD;">select * from author;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220208131425459.png" alt="image-20220208131425459" style="zoom:67%;"><h3 id="mysql主从复制" tabindex="-1">MySQL主从复制 <a class="header-anchor" href="#mysql主从复制" aria-label="Permalink to &quot;MySQL主从复制&quot;">​</a></h3><h4 id="主服务器配置" tabindex="-1">主服务器配置 <a class="header-anchor" href="#主服务器配置" aria-label="Permalink to &quot;主服务器配置&quot;">​</a></h4><p>新建主服务器容器实例3307</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">3307</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">3306</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name mysql</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">master </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydata</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">master</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">log:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">log</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydata</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">master</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydata</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">master</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">conf:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">e MYSQL_ROOT_PASSWORD</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">root  </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d mysql:</span><span style="color:#F78C6C;">5.7</span></span></code></pre></div><p>进入/mydata/mysql-master/conf目录下新建my.cnf</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">cd /mydata/mysql-master/conf</span></span>
<span class="line"><span style="color:#A6ACCD;">vim my.cnf</span></span></code></pre></div><div class="language-ini"><button title="Copy Code" class="copy"></button><span class="lang">ini</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">[mysqld]</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 设置server_id，同一局域网中需要唯一</span></span>
<span class="line"><span style="color:#F07178;">server_id</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">101 </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 指定不需要同步的数据库名称</span></span>
<span class="line"><span style="color:#F07178;">binlog-ignore-db</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mysql  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 开启二进制日志功能</span></span>
<span class="line"><span style="color:#F07178;">log-bin</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mall-mysql-bin  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 设置二进制日志使用内存大小（事务）</span></span>
<span class="line"><span style="color:#F07178;">binlog_cache_size</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">1M  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 设置使用的二进制日志格式（mixed,statement,row）</span></span>
<span class="line"><span style="color:#F07178;">binlog_format</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">row  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 二进制日志过期清理时间。默认值为0，表示不自动清理。</span></span>
<span class="line"><span style="color:#F07178;">expire_logs_days</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">7  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 跳过主从复制中遇到的所有错误或指定类型的错误，避免slave端复制中断。</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">## 如：1062错误是指一些主键重复，1032错误是因为主从数据库数据不一致</span></span>
<span class="line"><span style="color:#F07178;">slave_skip_errors</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">1062</span></span></code></pre></div><p>修改完配置后重启master实例</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker restart mysql-master</span></span></code></pre></div><p>master容器实例内创建数据同步用户</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F78C6C;">CREATE</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">USER</span><span style="color:#A6ACCD;"> &#39;</span><span style="color:#82AAFF;">slave</span><span style="color:#A6ACCD;">&#39;@</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">%</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;"> IDENTIFIED </span><span style="color:#F78C6C;">BY</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">123456</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">;</span></span>
<span class="line"><span style="color:#F78C6C;">GRANT</span><span style="color:#A6ACCD;"> REPLICATION SLAVE, REPLICATION CLIENT </span><span style="color:#F78C6C;">ON</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">*</span><span style="color:#A6ACCD;">.</span><span style="color:#89DDFF;">*</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">TO</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">slave</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">@</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">%</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">;</span></span></code></pre></div><h4 id="从服务器配置" tabindex="-1">从服务器配置 <a class="header-anchor" href="#从服务器配置" aria-label="Permalink to &quot;从服务器配置&quot;">​</a></h4><p>新建从服务器容器实例3308</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">3308</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">3306</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name mysql</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">slave </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydata</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">slave</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">log:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">log</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydata</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">slave</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydata</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">slave</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">conf:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">e MYSQL_ROOT_PASSWORD</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">root  </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d mysql:</span><span style="color:#F78C6C;">5.7</span></span></code></pre></div><p>进入/mydata/mysql-slave/conf目录下新建my.cnf</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">cd /mydata/mysql-slave/conf</span></span>
<span class="line"><span style="color:#A6ACCD;">vim my.cnf</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">[</span><span style="color:#A6ACCD;">mysqld</span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#89DDFF;">##</span><span style="color:#A6ACCD;"> 设置server_id，同一局域网中需要唯一</span></span>
<span class="line"><span style="color:#A6ACCD;">server_id</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">102</span></span>
<span class="line"><span style="color:#89DDFF;">##</span><span style="color:#A6ACCD;"> 指定不需要同步的数据库名称</span></span>
<span class="line"><span style="color:#A6ACCD;">binlog</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">ignore</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">db</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mysql  </span></span>
<span class="line"><span style="color:#89DDFF;">##</span><span style="color:#A6ACCD;"> 开启二进制日志功能，以备Slave作为其它数据库实例的Master时使用</span></span>
<span class="line"><span style="color:#A6ACCD;">log</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mall</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">slave1</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">bin  </span></span>
<span class="line"><span style="color:#89DDFF;">##</span><span style="color:#A6ACCD;"> 设置二进制日志使用内存大小（事务）</span></span>
<span class="line"><span style="color:#A6ACCD;">binlog_cache_size</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">1M</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"><span style="color:#89DDFF;">##</span><span style="color:#A6ACCD;"> 设置使用的二进制日志格式（mixed</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;">statement</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;">row）</span></span>
<span class="line"><span style="color:#A6ACCD;">binlog_format</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mixed  </span></span>
<span class="line"><span style="color:#89DDFF;">##</span><span style="color:#A6ACCD;"> 二进制日志过期清理时间。默认值为</span><span style="color:#F78C6C;">0</span><span style="color:#A6ACCD;">，表示不自动清理。</span></span>
<span class="line"><span style="color:#A6ACCD;">expire_logs_days</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">7</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"><span style="color:#89DDFF;">##</span><span style="color:#A6ACCD;"> 跳过主从复制中遇到的所有错误或指定类型的错误，避免slave端复制中断。</span></span>
<span class="line"><span style="color:#89DDFF;">##</span><span style="color:#A6ACCD;"> 如：</span><span style="color:#F78C6C;">1062</span><span style="color:#A6ACCD;">错误是指一些主键重复，</span><span style="color:#F78C6C;">1032</span><span style="color:#A6ACCD;">错误是因为主从数据库数据不一致</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;">all避开所有错误</span></span>
<span class="line"><span style="color:#A6ACCD;">slave_skip_errors</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">1062</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"><span style="color:#89DDFF;">##</span><span style="color:#A6ACCD;"> relay_log配置中继日志</span></span>
<span class="line"><span style="color:#A6ACCD;">relay_log</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">mall</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">relay</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">bin  </span></span>
<span class="line"><span style="color:#89DDFF;">##</span><span style="color:#A6ACCD;"> log_slave_updates表示slave将复制事件写进自己的二进制日志</span></span>
<span class="line"><span style="color:#A6ACCD;">log_slave_updates</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"><span style="color:#89DDFF;">##</span><span style="color:#A6ACCD;"> slave设置为只读（具有super权限的用户除外）</span></span>
<span class="line"><span style="color:#A6ACCD;">read_only</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">1</span></span></code></pre></div><p>修改完配置后重启slave实例</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker restart mysql-slave</span></span></code></pre></div><p>在主数据库中查看主从同步状态</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show master status;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220209104052301.png" alt="image-20220209104052301" style="zoom:80%;"><p>进入mysql-slave容器</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec -it mysql-slave /bin/bash</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql -uroot -proot</span></span></code></pre></div><p>在从数据库中配置主从复制</p><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">change master to master_host=&#39;192.168.22.145&#39;, </span></span>
<span class="line"><span style="color:#A6ACCD;">master_user=&#39;root&#39;, </span></span>
<span class="line"><span style="color:#A6ACCD;">master_password=&#39;123456&#39;, </span></span>
<span class="line"><span style="color:#A6ACCD;">master_port=3307, </span></span>
<span class="line"><span style="color:#A6ACCD;">master_log_file=&#39;mall-mysql-bin.000002&#39;, </span></span>
<span class="line"><span style="color:#A6ACCD;">master_log_pos=431, </span></span>
<span class="line"><span style="color:#A6ACCD;">master_connect_retry=30;</span></span></code></pre></div><p>主从复制命令参数说明</p><ul><li>master_host：主数据库的IP地址；</li><li>master_port：主数据库的运行端口；</li><li>master_user：在主数据库创建的用于同步数据的用户账号；</li><li>master_password：在主数据库创建的用于同步数据的用户密码；</li><li>master_log_file：指定从数据库要复制数据的日志文件，通过查看主数据的状态，获取File参数；</li><li>master_log_pos：指定从数据库从哪个位置开始复制数据，通过查看主数据的状态，获取Position参数；</li><li>master_connect_retry：连接失败重试的时间间隔，单位为秒。</li></ul><p>在从数据库中开启主从同步</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">start slave;</span></span></code></pre></div><p>查看从数据库状态发现已经同步</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">show slave status \G;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220209105228510.png" alt="image-20220209105228510" style="zoom:80%;"><h4 id="主从复制测试" tabindex="-1">主从复制测试 <a class="header-anchor" href="#主从复制测试" aria-label="Permalink to &quot;主从复制测试&quot;">​</a></h4><p>主机新建库-使用库-新建表-插入数据，ok</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F78C6C;">create</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">database</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">mydb01</span><span style="color:#A6ACCD;">;</span></span>
<span class="line"><span style="color:#F78C6C;">use</span><span style="color:#A6ACCD;"> mydb01;</span></span>
<span class="line"><span style="color:#F78C6C;">CREATE</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">TABLE</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">IF</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">NOT</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">EXISTS</span><span style="color:#A6ACCD;"> author(</span></span>
<span class="line"><span style="color:#A6ACCD;">	id </span><span style="color:#C792EA;">INT</span><span style="color:#A6ACCD;"> auto_increment </span><span style="color:#C792EA;">primary key</span><span style="color:#A6ACCD;">,</span></span>
<span class="line"><span style="color:#A6ACCD;">	</span><span style="color:#F78C6C;">name</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">VARCHAR</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">20</span><span style="color:#A6ACCD;">),</span></span>
<span class="line"><span style="color:#A6ACCD;">	country </span><span style="color:#C792EA;">VARCHAR</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">20</span><span style="color:#A6ACCD;">)</span></span>
<span class="line"><span style="color:#A6ACCD;">);</span></span>
<span class="line"><span style="color:#A6ACCD;"># 插入表内容</span></span>
<span class="line"><span style="color:#F78C6C;">INSERT INTO</span><span style="color:#A6ACCD;"> author </span><span style="color:#F78C6C;">VALUES</span><span style="color:#A6ACCD;">(</span><span style="color:#F78C6C;">null</span><span style="color:#A6ACCD;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">renshuo</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">,</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">zhonguo</span><span style="color:#89DDFF;">&#39;</span><span style="color:#A6ACCD;">);</span></span></code></pre></div><p>从机使用库-查看记录，ok</p><div class="language-sql"><button title="Copy Code" class="copy"></button><span class="lang">sql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F78C6C;">use</span><span style="color:#A6ACCD;"> mydb01;</span></span>
<span class="line"><span style="color:#F78C6C;">select</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">*</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">from</span><span style="color:#A6ACCD;"> author;</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220209115009974.png" alt="image-20220209115009974" style="zoom:80%;"><h2 id="部署tomcat" tabindex="-1">部署Tomcat <a class="header-anchor" href="#部署tomcat" aria-label="Permalink to &quot;部署Tomcat&quot;">​</a></h2><h3 id="实用版-1" tabindex="-1">实用版 <a class="header-anchor" href="#实用版-1" aria-label="Permalink to &quot;实用版&quot;">​</a></h3><ol><li>搜索tomcat镜像</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">search</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">tomcat</span></span></code></pre></div><ol start="2"><li>拉取tomcat镜像</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">pull</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">tomcat</span></span></code></pre></div><ol start="3"><li>创建容器，设置端口映射、目录映射</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 在/root目录下创建tomcat目录用于存储tomcat数据信息</span></span>
<span class="line"><span style="color:#FFCB6B;">mkdir</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">~/tomcat</span></span>
<span class="line"><span style="color:#82AAFF;">cd</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">~/tomcat</span></span></code></pre></div><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-id</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--name=c_tomcat</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-p </span><span style="color:#F78C6C;">8089</span><span style="color:#C3E88D;">:8080</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v $PWD</span><span style="color:#C3E88D;">:/usr/local/tomcat/webapps</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">tomcat</span></span></code></pre></div><ul><li><p>参数说明：</p><ul><li><p>**-p 8080:8080：**将容器的8080端口映射到主机的8080端口</p><p>**-v $PWD:/usr/local/tomcat/webapps：**将主机中当前目录挂载到容器的webapps</p></li></ul></li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mkdir test</span></span>
<span class="line"><span style="color:#A6ACCD;">cd test</span></span>
<span class="line"><span style="color:#A6ACCD;">vim index.html</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005161757344.png" alt="image-20211005161757344" style="zoom:80%;"><ol start="4"><li>使用外部机器访问tomcat</li></ol><p>访问网址：<a href="http://192.168.220.128:8080/test/index.html" target="_blank" rel="noreferrer">http://192.168.220.128:8080/test/index.html</a> 因为是在test文件下下创建的index.html，所以访问地址是这个</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005161702102.png" alt="image-20211005161702102" style="zoom:67%;"><h3 id="错误处理" tabindex="-1">错误处理 <a class="header-anchor" href="#错误处理" aria-label="Permalink to &quot;错误处理&quot;">​</a></h3><p>启动时访问该网站发现404，不能进入带猫首页</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">http://192.168.220.130:8080/</span></span></code></pre></div><p>可能出错原因</p><ul><li>可能没有映射端口或者没有关闭防火墙</li><li>把webapps.dist目录换成webapps，先成功启动tomcat，查看webapps 文件夹查看为空</li></ul><p>解决方式</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker ps</span></span>
<span class="line"><span style="color:#A6ACCD;">docker exec -it 60a86cfe932c bash</span></span>
<span class="line"><span style="color:#A6ACCD;">cd webapps.dist</span></span>
<span class="line"><span style="color:#A6ACCD;">mv * /usr/local/tomcat/webapps</span></span></code></pre></div><p>这样就能访问了，无需重启tomcat</p><p>因为新版tomcat把内容设置在了webapps.dist目录里，webapps里面没有东西，自然访问会报404错误</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220208165355119.png" alt="image-20220208165355119" style="zoom:80%;"><h3 id="简易版" tabindex="-1">简易版 <a class="header-anchor" href="#简易版" aria-label="Permalink to &quot;简易版&quot;">​</a></h3><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker pull billygoo/tomcat8-jdk8</span></span>
<span class="line"><span style="color:#A6ACCD;">docker run -d -p 8080:8080 --name mytomcat8 billygoo/tomcat8-jdk8</span></span></code></pre></div><p>外部进行访问</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">http://192.168.220.130:8080/</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220208161641056.png" alt="image-20220208161641056" style="zoom:67%;"><h2 id="部署nginx" tabindex="-1">部署Nginx <a class="header-anchor" href="#部署nginx" aria-label="Permalink to &quot;部署Nginx&quot;">​</a></h2><ol><li>搜索nginx镜像</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">search</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx</span></span></code></pre></div><ol start="2"><li>拉取nginx镜像</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">pull</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx</span></span></code></pre></div><ol start="3"><li>创建容器，设置端口映射、目录映射</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 在/root目录下创建nginx目录用于存储nginx数据信息</span></span>
<span class="line"><span style="color:#FFCB6B;">mkdir</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">~/nginx</span></span>
<span class="line"><span style="color:#82AAFF;">cd</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">~/nginx</span></span>
<span class="line"><span style="color:#FFCB6B;">mkdir</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">conf</span></span>
<span class="line"><span style="color:#82AAFF;">cd</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">conf</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 在~/nginx/conf/下创建nginx.conf文件,粘贴下面内容</span></span>
<span class="line"><span style="color:#FFCB6B;">vim</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx.conf</span></span></code></pre></div><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">user</span><span style="color:#A6ACCD;">  </span><span style="color:#C3E88D;">nginx</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#FFCB6B;">worker_processes</span><span style="color:#A6ACCD;">  </span><span style="color:#F78C6C;">1</span><span style="color:#89DDFF;">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#FFCB6B;">error_log</span><span style="color:#A6ACCD;">  </span><span style="color:#C3E88D;">/var/log/nginx/error.log</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">warn</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#FFCB6B;">pid</span><span style="color:#A6ACCD;">        </span><span style="color:#C3E88D;">/var/run/nginx.pid</span><span style="color:#89DDFF;">;</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#FFCB6B;">events</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">{</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">worker_connections</span><span style="color:#A6ACCD;">  </span><span style="color:#F78C6C;">1024</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">}</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#FFCB6B;">http</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">{</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">include</span><span style="color:#A6ACCD;">       </span><span style="color:#C3E88D;">/etc/nginx/mime.types</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">default_type</span><span style="color:#A6ACCD;">  </span><span style="color:#C3E88D;">application/octet-stream</span><span style="color:#89DDFF;">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">log_format</span><span style="color:#A6ACCD;">  </span><span style="color:#C3E88D;">main</span><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">$remote_addr - $remote_user [$time_local] &quot;$request&quot; </span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#A6ACCD;">                      </span><span style="color:#FFCB6B;">&#39;$status $body_bytes_sent &quot;$http_referer&quot; &#39;</span></span>
<span class="line"><span style="color:#A6ACCD;">                      </span><span style="color:#FFCB6B;">&#39;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;&#39;</span><span style="color:#89DDFF;">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">access_log</span><span style="color:#A6ACCD;">  </span><span style="color:#C3E88D;">/var/log/nginx/access.log</span><span style="color:#A6ACCD;">  </span><span style="color:#C3E88D;">main</span><span style="color:#89DDFF;">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">sendfile</span><span style="color:#A6ACCD;">        </span><span style="color:#C3E88D;">on</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#676E95;font-style:italic;">#tcp_nopush     on;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">keepalive_timeout</span><span style="color:#A6ACCD;">  </span><span style="color:#F78C6C;">65</span><span style="color:#89DDFF;">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#676E95;font-style:italic;">#gzip  on;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">include</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/etc/nginx/conf.d/</span><span style="color:#A6ACCD;">*</span><span style="color:#C3E88D;">.conf</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">}</span></span></code></pre></div><p>要先cd .. 切换到上一级的nginx目录，才能执行</p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-id</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--name=e_nginx</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-p </span><span style="color:#F78C6C;">80</span><span style="color:#C3E88D;">:80</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v $PWD</span><span style="color:#C3E88D;">/conf/nginx.conf:/etc/nginx/nginx.conf</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v $PWD</span><span style="color:#C3E88D;">/logs:/var/log/nginx</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v $PWD</span><span style="color:#C3E88D;">/html:/usr/share/nginx/html</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">nginx</span></span></code></pre></div><ul><li>参数说明： <ul><li><strong>-p 80:80</strong>：将容器的 80端口映射到宿主机的 80 端口。</li><li><strong>-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf</strong>：将主机当前目录下的 /conf/nginx.conf 挂载到容器的 :/etc/nginx/nginx.conf。配置目录</li><li><strong>-v $PWD/logs:/var/log/nginx</strong>：将主机当前目录下的 logs 目录挂载到容器的/var/log/nginx。日志目录</li></ul></li></ul><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005163641819.png" alt="image-20211005163641819" style="zoom:80%;"><ol start="4"><li>使用外部机器访问nginx</li></ol><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005163659672.png" alt="image-20211005163659672" style="zoom:67%;"><h2 id="部署redis" tabindex="-1">部署Redis <a class="header-anchor" href="#部署redis" aria-label="Permalink to &quot;部署Redis&quot;">​</a></h2><h3 id="简单使用" tabindex="-1">简单使用 <a class="header-anchor" href="#简单使用" aria-label="Permalink to &quot;简单使用&quot;">​</a></h3><ol><li>搜索redis镜像</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">search</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">redis</span></span></code></pre></div><ol start="2"><li>拉取redis镜像</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">pull</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">redis:6.0.8</span></span></code></pre></div><ol start="3"><li>创建容器，设置端口映射</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-id</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--name=c_redis</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">6379</span><span style="color:#C3E88D;">:6379</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">redis:6.0.8</span></span></code></pre></div><ol start="4"><li>使用外部机器连接redis</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">redis-cli.exe</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-h</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">192.168</span><span style="color:#C3E88D;">.220.130</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">6379</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005164234847.png" alt="image-20211005164234847" style="zoom:80%;"><p>内部进入使用</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker ps</span></span>
<span class="line"><span style="color:#A6ACCD;">docker exec -it c_redis bash</span></span>
<span class="line"><span style="color:#A6ACCD;">redis-cli</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220208145105383.png" alt="image-20220208145105383" style="zoom:80%;"><h3 id="配置文件启动⭐⭐" tabindex="-1">配置文件启动⭐⭐ <a class="header-anchor" href="#配置文件启动⭐⭐" aria-label="Permalink to &quot;配置文件启动⭐⭐&quot;">​</a></h3><p>在CentOS宿主机下新建目录，并创建配置文件，任意redis配置文件即可，网上可以搜到，粘贴就行。或者直接复制其他redis的配置文件redis.conf</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mkdir </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span></span>
<span class="line"><span style="color:#A6ACCD;">cd </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span></span>
<span class="line"><span style="color:#A6ACCD;">vi redis</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">conf</span></span></code></pre></div><p><strong>redis.conf配置文件修改</strong></p><ul><li>开启redis验证， <strong>可选，requirepass 123</strong></li><li>允许redis外地连接 <strong>必须注释掉 # bind 127.0.0.1</strong></li><li>daemonize no 将daemonize yes注释起来或者 daemonize no设置，因为该配置和docker run中-d参数冲突，会导致容器一直启动失败</li><li>开启redis数据持久化 appendonly yes 可选</li></ul><p>使用redis6.0.8镜像创建容器(也叫运行镜像)</p><p>命令提醒：容器卷记得加入--privileged=true</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;">  </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">6379</span><span style="color:#C3E88D;">:6379</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">--name </span><span style="color:#C3E88D;">myr3</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">--privileged=true \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/redis/redis.conf:/etc/redis/redis.conf</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v </span><span style="color:#C3E88D;">/DockerData/redis/data:/data</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">-d </span><span style="color:#C3E88D;">redis:6.0.8</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">redis-server </span><span style="color:#C3E88D;">/etc/redis/redis.conf</span></span></code></pre></div><p>测试redis-cli连接上来</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker ps</span></span>
<span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it myr3 </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span>
<span class="line"><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">cli</span></span>
<span class="line"><span style="color:#A6ACCD;">set name wangrui</span></span>
<span class="line"><span style="color:#A6ACCD;">get name</span></span></code></pre></div><h3 id="测试是否使用了配置文件" tabindex="-1">测试是否使用了配置文件 <a class="header-anchor" href="#测试是否使用了配置文件" aria-label="Permalink to &quot;测试是否使用了配置文件&quot;">​</a></h3><p>redis默认有16个数据库，此时我们修改成14个数据库</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">vi </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">conf</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220208151950306.png" alt="image-20220208151950306" style="zoom:67%;"><p>重启redis容器并进入</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker restart  b8bda63b7950</span></span>
<span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it myr3 </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span>
<span class="line"><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">cli</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220208152808079.png" alt="image-20220208152808079" style="zoom:67%;"><p>删除容器，测试之前的数据是否存在</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker rm </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f b8bda63b7950</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run  </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">6379</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">6379</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name myr3 </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">privileged</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">true </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">conf:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">conf </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d redis:</span><span style="color:#F78C6C;">6.0.8</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">server </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">conf</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it myr3 </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span>
<span class="line"><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">cli</span></span>
<span class="line"><span style="color:#A6ACCD;">get name</span></span></code></pre></div><p>数据依然存在，可以获取到name</p><h2 id="部署python" tabindex="-1">部署Python <a class="header-anchor" href="#部署python" aria-label="Permalink to &quot;部署Python&quot;">​</a></h2><h3 id="新建python" tabindex="-1">新建Python <a class="header-anchor" href="#新建python" aria-label="Permalink to &quot;新建Python&quot;">​</a></h3><p>这里为了演示的方便，我们就写一个简单的<code>Flask</code>项目，代码如下</p><div class="language-python"><button title="Copy Code" class="copy"></button><span class="lang">python</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;font-style:italic;">from</span><span style="color:#A6ACCD;"> flask </span><span style="color:#89DDFF;font-style:italic;">import</span><span style="color:#A6ACCD;"> Flask</span></span>
<span class="line"><span style="color:#A6ACCD;">app </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">Flask</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">__name__</span><span style="color:#89DDFF;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;">@</span><span style="color:#82AAFF;">app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">route</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">/</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">)</span></span>
<span class="line"><span style="color:#C792EA;">def</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">index</span><span style="color:#89DDFF;">():</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;font-style:italic;">return</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">Hello World!</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#89DDFF;font-style:italic;">if</span><span style="color:#A6ACCD;"> __name__ </span><span style="color:#89DDFF;">==</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">__main__</span><span style="color:#89DDFF;">&#39;</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    app</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">run</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;font-style:italic;">host</span><span style="color:#89DDFF;">=</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">0.0.0.0</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#82AAFF;"> </span><span style="color:#A6ACCD;font-style:italic;">port</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">5000</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;font-style:italic;">debug</span><span style="color:#89DDFF;">=True)</span></span></code></pre></div><p>显而易见，就是一个非常基础的项目，当我们在浏览器输入网址以及对应的端口号的时候，会返回“Hello World!”内容</p><h3 id="dockerfile文件" tabindex="-1">DockerFile文件 <a class="header-anchor" href="#dockerfile文件" aria-label="Permalink to &quot;DockerFile文件&quot;">​</a></h3><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;">#设置python环境镜像</span></span>
<span class="line"><span style="color:#FFCB6B;">FROM</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">python:3.6</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 设置src文件夹是工作目录</span></span>
<span class="line"><span style="color:#FFCB6B;">WORKDIR</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/src</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 安装相应的python库</span></span>
<span class="line"><span style="color:#FFCB6B;">RUN</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">pip</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">install</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-r</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">requirements.txt</span></span>
<span class="line"></span>
<span class="line"><span style="color:#FFCB6B;">COPY</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">.</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">.</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 执行Python程序（网页程序主程序）</span></span>
<span class="line"><span style="color:#FFCB6B;">CMD</span><span style="color:#A6ACCD;"> [</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">python3</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;">, </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">src/app.py</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">]</span></span></code></pre></div><h3 id="创建镜像" tabindex="-1">创建镜像 <a class="header-anchor" href="#创建镜像" aria-label="Permalink to &quot;创建镜像&quot;">​</a></h3><p>我们进入到项目目录当中，先来查看一下当前的镜像</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">images</span></span></code></pre></div><p>然后我们开始创建网页程序的镜像</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">build</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-t</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker_flask_image</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">.</span></span></code></pre></div><p><code>docker build</code>命令主要是用于创建镜像，当中的参数<code>-tag</code>，<code>-t</code> 代表的是镜像的名字及标签</p><h3 id="运行镜像容器" tabindex="-1">运行镜像容器 <a class="header-anchor" href="#运行镜像容器" aria-label="Permalink to &quot;运行镜像容器&quot;">​</a></h3><p>使用<code>docker run</code>命令基于镜像运行一个容器，其中常用的参数有</p><ul><li><code>-d</code> 代表容器在后台运行，不是基于前台运行</li><li><code>--name</code> 代表执行容易的别名</li><li><code>-p</code>：用于配置宿主机与容器的端口映射</li></ul><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">sudo</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-d</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--name</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">flask_web</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">5000</span><span style="color:#C3E88D;">:5000</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker_flask_image</span></span></code></pre></div><h3 id="测试实践" tabindex="-1">测试实践 <a class="header-anchor" href="#测试实践" aria-label="Permalink to &quot;测试实践&quot;">​</a></h3><p>最后我们在浏览器中，访问一下该网页，要是你用到的是远程服务器，则需要用到公网的IP，对应的端口号是5000</p><p>可以看到网页访问成功了，出来一个“Hello World!”的页面，这样我们网页程序就成功部署在了<code>Docker</code>当中</p><h1 id="安装redis集群" tabindex="-1">安装Redis集群 <a class="header-anchor" href="#安装redis集群" aria-label="Permalink to &quot;安装Redis集群&quot;">​</a></h1><p><strong>一个集群只能有16384个槽</strong>，编号0-16383（0-2^14-1）。这些槽会分配给集群中的所有主节点，分配策略没有要求。可以指定哪些编号的槽分配给哪个主节点。集群会记录节点和槽的对应关系。解决了节点和槽的关系后，接下来就需要对key求哈希值，然后对16384取余，余数是几key就落入对应的槽里。slot = CRC16(key) % 16384。以槽为单位移动数据，因为槽的数目是固定的，处理起来比较容易，这样数据移动问题就解决了。</p><p>哈希槽计算</p><p>Redis 集群中内置了 16384 个哈希槽，<strong>redis 会根据节点数量大致均等的将哈希槽映射到不同的节点</strong>。当需要在 Redis 集群中放置一个 key-value时，redis 先对 key 使用 crc16 算法算出一个结果，然后把结果对 16384 求余数，这样每个 key 都会对应一个编号在 0-16383 之间的哈希槽，也就是映射到某个节点上。如下代码，key之A 、B在Node2， key之C落在Node3上。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220214125244088.png" alt="image-20220214125244088" style="zoom:80%;"><p>引入import io.lettuce.core.cluster.SlotHash;</p><div class="language-xml"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">dependency</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">io.lettuce</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">lettuce-core</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">6.0.1.RELEASE</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">version</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">scope</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">test</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">scope</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">dependency</span><span style="color:#89DDFF;">&gt;</span></span></code></pre></div><div class="language-java"><button title="Copy Code" class="copy"></button><span class="lang">java</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">@</span><span style="color:#C792EA;">Test</span></span>
<span class="line"><span style="color:#C792EA;">public</span><span style="color:#A6ACCD;"> </span><span style="color:#C792EA;">void</span><span style="color:#A6ACCD;"> </span><span style="color:#82AAFF;">testHash</span><span style="color:#89DDFF;">()</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#A6ACCD;">   System</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">out</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">println</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">SlotHash</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">getSlot</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">A</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">));</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;">//6373</span></span>
<span class="line"><span style="color:#A6ACCD;">   System</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">out</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">println</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">SlotHash</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">getSlot</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">任硕</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">));</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;">//14436</span></span>
<span class="line"><span style="color:#A6ACCD;">   System</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">out</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">println</span><span style="color:#89DDFF;">(</span><span style="color:#A6ACCD;">SlotHash</span><span style="color:#89DDFF;">.</span><span style="color:#82AAFF;">getSlot</span><span style="color:#89DDFF;">(</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">张飞</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">));</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;">//5024</span></span>
<span class="line"><span style="color:#89DDFF;">}</span></span></code></pre></div><h2 id="集群配置" tabindex="-1">集群配置 <a class="header-anchor" href="#集群配置" aria-label="Permalink to &quot;集群配置&quot;">​</a></h2><h3 id="三主三从" tabindex="-1">三主三从 <a class="header-anchor" href="#三主三从" aria-label="Permalink to &quot;三主三从&quot;">​</a></h3><p>新建6个docker容器redis实例</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">net host </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">privileged</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">true </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">share</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">1</span><span style="color:#A6ACCD;">:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data redis:</span><span style="color:#F78C6C;">6.0.8</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">cluster</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">enabled yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">appendonly yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">port </span><span style="color:#F78C6C;">6381</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">2</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">net host </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">privileged</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">true </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">share</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">2</span><span style="color:#A6ACCD;">:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data redis:</span><span style="color:#F78C6C;">6.0.8</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">cluster</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">enabled yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">appendonly yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">port </span><span style="color:#F78C6C;">6382</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">3</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">net host </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">privileged</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">true </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">share</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">3</span><span style="color:#A6ACCD;">:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data redis:</span><span style="color:#F78C6C;">6.0.8</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">cluster</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">enabled yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">appendonly yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">port </span><span style="color:#F78C6C;">6383</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">4</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">net host </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">privileged</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">true </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">share</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">4</span><span style="color:#A6ACCD;">:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data redis:</span><span style="color:#F78C6C;">6.0.8</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">cluster</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">enabled yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">appendonly yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">port </span><span style="color:#F78C6C;">6384</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">5</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">net host </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">privileged</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">true </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">share</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">5</span><span style="color:#A6ACCD;">:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data redis:</span><span style="color:#F78C6C;">6.0.8</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">cluster</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">enabled yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">appendonly yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">port </span><span style="color:#F78C6C;">6385</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">6</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">net host </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">privileged</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">true </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">share</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">6</span><span style="color:#A6ACCD;">:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data redis:</span><span style="color:#F78C6C;">6.0.8</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">cluster</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">enabled yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">appendonly yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">port </span><span style="color:#F78C6C;">6386</span></span></code></pre></div><p>启动成功</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210095647516.png" alt="image-20220210095647516" style="zoom:80%;"><p>命令分步解释</p><ul><li>docker run ：创建并运行docker容器实例</li><li>--name redis-node-6 ：容器名字</li><li>--net host ：使用宿主机的IP和端口，默认</li><li>--privileged=true ： 获取宿主机root用户权限</li><li>-v /data/redis/share/redis-node-6:/data：容器卷，宿主机地址:docker内部地址</li><li>redis:6.0.8 ：redis镜像和版本号</li><li>--cluster-enabled yes ：开启redis集群</li><li>--appendonly yes ：开启持久化</li><li>--port 6386 ：redis端口号</li></ul><p>进入容器</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec -it redis-node-1 /bin/bash</span></span></code></pre></div><p>构建主从关系(三主三从)</p><p>注意，进入docker容器后才能执行一下命令，且注意自己的真实IP地址</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster \</span></span>
<span class="line"><span style="color:#A6ACCD;">create \</span></span>
<span class="line"><span style="color:#A6ACCD;">192.168.220.130:6381 \</span></span>
<span class="line"><span style="color:#A6ACCD;">192.168.220.130:6382 \</span></span>
<span class="line"><span style="color:#A6ACCD;">192.168.220.130:6383 \</span></span>
<span class="line"><span style="color:#A6ACCD;">192.168.220.130:6384 \</span></span>
<span class="line"><span style="color:#A6ACCD;">192.168.220.130:6385 \</span></span>
<span class="line"><span style="color:#A6ACCD;">192.168.220.130:6386 \</span></span>
<span class="line"><span style="color:#A6ACCD;">--cluster-replicas 1</span></span></code></pre></div><p>--cluster-replicas 1 <strong>表示为每个master创建一个slave节点</strong></p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210101417584.png" alt="image-20220210101417584" style="zoom:67%;"><p>一切OK的话，3主3从搞定</p><h3 id="普通使用" tabindex="-1">普通使用 <a class="header-anchor" href="#普通使用" aria-label="Permalink to &quot;普通使用&quot;">​</a></h3><p>链接进入6381作为切入点，查看集群状态</p><p>必须加上-c，表示以集群方式进入，注意看节点之间的切换</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli -p 6381 -c</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210101751207.png" alt="image-20220210101751207" style="zoom:67%;"><p>查看集群状态</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">cluster info</span></span>
<span class="line"><span style="color:#A6ACCD;">cluster nodes</span></span></code></pre></div><p>查看集群信息</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster check 192.168.220.130:6381</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210115112648.png" alt="image-20220210115112648" style="zoom:67%;"><h3 id="容错切换迁移" tabindex="-1">容错切换迁移 <a class="header-anchor" href="#容错切换迁移" aria-label="Permalink to &quot;容错切换迁移&quot;">​</a></h3><p>主6381和从机切换，先停止主机6381</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker stop redis-node-1</span></span></code></pre></div><p>6381主机停了，对应的真实从机上位，6381作为1号主机分配的从机以实际情况为准，具体是几号机器就是几号</p><p>再次查看集群状态，已经有一个从节点变成主节点，就是三主两从</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec -it redis-node-2 /bin/bash</span></span>
<span class="line"><span style="color:#A6ACCD;">redis-cli -p 6382 -c</span></span>
<span class="line"><span style="color:#A6ACCD;">cluster nodes</span></span></code></pre></div><p>再次重启node1节点，中间需要等待一会儿，docker集群重新响应</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker start redis-node-1</span></span>
<span class="line"><span style="color:#A6ACCD;">docker stop redis-node-5</span></span>
<span class="line"><span style="color:#A6ACCD;">docker start redis-node-5</span></span></code></pre></div><p>查看集群状态</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster check 192.168.220.130:6381</span></span></code></pre></div><h3 id="主从扩容案例" tabindex="-1">主从扩容案例 <a class="header-anchor" href="#主从扩容案例" aria-label="Permalink to &quot;主从扩容案例&quot;">​</a></h3><p>新建6387、6388两个节点+新建后启动+查看是否8节点</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">7</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">net host </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">privileged</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">true </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">share</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">7</span><span style="color:#A6ACCD;">:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data redis:</span><span style="color:#F78C6C;">6.0.8</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">cluster</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">enabled yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">appendonly yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">port </span><span style="color:#F78C6C;">6387</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">8</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">net host </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">privileged</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">true </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">share</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">node</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">8</span><span style="color:#A6ACCD;">:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data redis:</span><span style="color:#F78C6C;">6.0.8</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">cluster</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">enabled yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">appendonly yes </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">port </span><span style="color:#F78C6C;">6388</span></span></code></pre></div><p>查看状态</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker ps</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210115926028.png" alt="image-20220210115926028" style="zoom:67%;"><p>进入6387容器实例内部</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec -it redis-node-7 /bin/bash</span></span></code></pre></div><p>将新增的6387节点(空槽号)作为master节点加入原集群</p><p>将新增的6387作为master节点加入集群0</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster add-node 自己实际IP地址:6387 自己实际IP地址:6381 </span></span>
<span class="line"><span style="color:#A6ACCD;">redis-cli --cluster add-node 192.168.220.130:6387 192.168.220.130:6381</span></span></code></pre></div><p>6387 就是将要作为master新增节点 6381 就是原来集群节点里面的领路人，相当于6387拜拜6381的码头从而找到组织加入集群</p><p>检查集群情况第1次</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster check 192.168.220.130:6381</span></span></code></pre></div><p>重新分派槽号</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">命令:redis-cli --cluster reshard IP地址:端口号</span></span>
<span class="line"><span style="color:#A6ACCD;">redis-cli --cluster reshard 192.168.111.147:6381</span></span></code></pre></div><p>依次输入4096、6387节点ID、all即可</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210145737795.png" alt="image-20220210145737795" style="zoom:67%;"><p>检查集群情况第2次</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster check 192.168.220.130:6381</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210150004360.png" alt="image-20220210150004360" style="zoom:67%;"><p>为什么6387是3个新的区间，以前的还是连续？ 重新分配成本太高，所以前3家各自匀出来一部分，从6381/6382/6383三个旧节点分别匀出1364个坑位给新节点6387</p><p>命令：</p><p>查看6387编号</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli -p 6381 -c</span></span>
<span class="line"><span style="color:#A6ACCD;">cluster nodes</span></span></code></pre></div><p>为主节点6387分配从节点6388</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster add-node ip:新slave端口 ip:新master端口 --cluster-slave --cluster-master-id 新主机节点ID</span></span>
<span class="line"><span style="color:#A6ACCD;"></span></span>
<span class="line"><span style="color:#A6ACCD;">redis-cli --cluster add-node 192.168.220.130:6388 192.168.220.130:6387 --cluster-slave --cluster-master-id f32f4d991f61daae5efbdc24fb438db7e90ba5f6 -------这个是6387的编号，按照自己实际情况</span></span></code></pre></div><p>检查集群情况第3次</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster check 192.168.220.130:6382</span></span></code></pre></div><h3 id="主从缩容案例" tabindex="-1">主从缩容案例 <a class="header-anchor" href="#主从缩容案例" aria-label="Permalink to &quot;主从缩容案例&quot;">​</a></h3><p>目的：6387和6388下线</p><h4 id="删除从节点6388" tabindex="-1">删除从节点6388 <a class="header-anchor" href="#删除从节点6388" aria-label="Permalink to &quot;删除从节点6388&quot;">​</a></h4><p>检查集群情况1获得6388的节点ID</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster check 192.168.220.130:6382</span></span></code></pre></div><p>将6388删除 从集群中将4号从节点6388删除</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster del-node ip:从机端口 从机6388节点ID</span></span></code></pre></div><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster del-node 192.168.220.130:6388 31120936be8780547f2d5031359275b1c71ad319</span></span></code></pre></div><p>检查一下还剩几个节点</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster check 192.168.220.130:6382</span></span></code></pre></div><p>此时还剩7个节点</p><h4 id="删除主节点6387" tabindex="-1">删除主节点6387 <a class="header-anchor" href="#删除主节点6387" aria-label="Permalink to &quot;删除主节点6387&quot;">​</a></h4><p>将6387的槽号清空，重新分配，本例将清出来的槽号都给6382</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster reshard 192.168.220.130:6382</span></span></code></pre></div><p>依次输入4096、6382节点ID、6387节点ID、done即可</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210153832415.png" alt="image-20220210153832415" style="zoom:67%;"><p>node2节点ID是用来接收node7删除后留下来的槽号</p><p>node7节点ID是要删除的节点</p><p>最后输入yes完事</p><p>检查集群情况第二次</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster check 192.168.220.130:6382</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">4096个槽位都指给6382，它变成了8192个槽位，相当于全部都给6382了，不然要输入3次，一锅端</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210153017964.png" alt="image-20220210153017964" style="zoom:67%;"><p>将6387删除</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">命令：redis-cli --cluster del-node ip:端口 6387节点ID</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">redis-cli --cluster del-node 192.168.220.130:6387 f32f4d991f61daae5efbdc24fb438db7e90ba5f6</span></span></code></pre></div><p>检查集群情况第三次</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis-cli --cluster check 192.168.220.130:6381</span></span></code></pre></div><p>此时只剩6个节点，三主三从，7号节点成功删除</p><h1 id="dockerfile⭐⭐" tabindex="-1">Dockerfile⭐⭐ <a class="header-anchor" href="#dockerfile⭐⭐" aria-label="Permalink to &quot;Dockerfile⭐⭐&quot;">​</a></h1><h2 id="是什么" tabindex="-1">是什么 <a class="header-anchor" href="#是什么" aria-label="Permalink to &quot;是什么&quot;">​</a></h2><p>构建自定义的镜像时，并不需要一个个文件去拷贝，打包。</p><p>我们只需要告诉Docker，我们的镜像的组成，需要哪些BaseImage、需要拷贝什么文件、需要安装什么依赖、启动脚本是什么，将来Docker会帮助我们构建镜像。</p><p>而描述上述信息的文件就是Dockerfile文件。</p><p><strong>Dockerfile</strong>就是一个文本文件，其中包含一个个的<strong>指令(Instruction)</strong>，用指令来说明要执行什么操作来构建镜像。每一个指令都会形成一层Layer。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011207491.png" alt="image-20220901120713347" style="zoom:67%;"><h2 id="基本指令" tabindex="-1">基本指令 <a class="header-anchor" href="#基本指令" aria-label="Permalink to &quot;基本指令&quot;">​</a></h2><p><a href="https://docs.docker.com/engine/reference/builder/" target="_blank" rel="noreferrer">Dockerfile reference |Docker 文档</a></p><h3 id="指令分析" tabindex="-1">指令分析 <a class="header-anchor" href="#指令分析" aria-label="Permalink to &quot;指令分析&quot;">​</a></h3><p><img src="https://images2017.cnblogs.com/blog/911490/201712/911490-20171208222222062-849020400.png" alt="img"></p><h3 id="构建和运行" tabindex="-1">构建和运行 <a class="header-anchor" href="#构建和运行" aria-label="Permalink to &quot;构建和运行&quot;">​</a></h3><p>构建</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker build -t 新镜像名字:TAG .</span></span></code></pre></div><p>运行</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run -it 新镜像名字:TAG</span></span></code></pre></div><h2 id="案例" tabindex="-1">案例 <a class="header-anchor" href="#案例" aria-label="Permalink to &quot;案例&quot;">​</a></h2><h3 id="自定义centos7镜像1" tabindex="-1">自定义centos7镜像1 <a class="header-anchor" href="#自定义centos7镜像1" aria-label="Permalink to &quot;自定义centos7镜像1&quot;">​</a></h3><p>1、创建一个目录用于存放 dockerfile 文件便于统一管理</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mkdir dockerfile &amp;&amp; cd dockerfile</span></span></code></pre></div><p>2、下载阿里的 Centos repo 文件替换自带源提高下载速度</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">wget -O CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo</span></span></code></pre></div><p>3、编写 DockerFile 文件</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">vim custom-centos</span></span></code></pre></div><p>4、Dockerfile内容</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">vim custom-centos</span></span></code></pre></div><div class="language-dockerfile"><button title="Copy Code" class="copy"></button><span class="lang">dockerfile</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 使用官方基础镜像</span></span>
<span class="line"><span style="color:#F78C6C;">FROM</span><span style="color:#A6ACCD;"> centos   </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 镜像作者信息</span></span>
<span class="line"><span style="color:#F78C6C;">MAINTAINER</span><span style="color:#A6ACCD;"> Lamdaer&lt;huangzijian888@gmail.com&gt; </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 自定义环境变量 MYPATH</span></span>
<span class="line"><span style="color:#F78C6C;">ENV</span><span style="color:#A6ACCD;"> MYPATH /usr/local  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 工作目录</span></span>
<span class="line"><span style="color:#F78C6C;">WORKDIR</span><span style="color:#A6ACCD;"> $MYPATH        </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 添加阿里镜像提高下载速度</span></span>
<span class="line"><span style="color:#F78C6C;">ADD</span><span style="color:#A6ACCD;"> CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 更新</span></span>
<span class="line"><span style="color:#F78C6C;">RUN</span><span style="color:#A6ACCD;"> yum -y update</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 安装 vim</span></span>
<span class="line"><span style="color:#F78C6C;">RUN</span><span style="color:#A6ACCD;"> yum -y install vim     </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 安装 net-tools</span></span>
<span class="line"><span style="color:#F78C6C;">RUN</span><span style="color:#A6ACCD;"> yum -y install net-tools  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 暴露 80 端口</span></span>
<span class="line"><span style="color:#F78C6C;">EXPOSE</span><span style="color:#A6ACCD;"> 80 </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 输出自定义环境变量</span></span>
<span class="line"><span style="color:#F78C6C;">CMD</span><span style="color:#A6ACCD;"> echo $MYPATH     </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 输出 end </span></span>
<span class="line"><span style="color:#F78C6C;">CMD</span><span style="color:#A6ACCD;"> echo </span><span style="color:#C3E88D;">&quot;----end----&quot;</span><span style="color:#A6ACCD;">  </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 默认终端</span></span>
<span class="line"><span style="color:#F78C6C;">CMD</span><span style="color:#A6ACCD;"> /bin/bash</span></span></code></pre></div><p>5、构建</p><div class="language-dockerfile"><button title="Copy Code" class="copy"></button><span class="lang">dockerfile</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker build -f custom-centos  -t mycentos:0.1 .</span></span>
<span class="line"></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 参数含义</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># -f 指定 DockerFile 文件</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># -t 指定构建后的镜像名称及版本 格式：镜像名称:版本号</span></span></code></pre></div><p>6、运行</p><div class="language-dockerfile"><button title="Copy Code" class="copy"></button><span class="lang">dockerfile</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run -it mycentos:0.1</span></span></code></pre></div><h3 id="自定义centos7镜像2" tabindex="-1">自定义centos7镜像2 <a class="header-anchor" href="#自定义centos7镜像2" aria-label="Permalink to &quot;自定义centos7镜像2&quot;">​</a></h3><p>自定义centos7镜像。要求：</p><ol><li><p>默认登录路径为 /usr</p></li><li><p>可以使用vim</p></li></ol><p>实现步骤</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;">定义父镜像：</span></span>
<span class="line"><span style="color:#A6ACCD;">FROM centos:</span><span style="color:#F78C6C;">7</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;">定义作者信息：</span></span>
<span class="line"><span style="color:#A6ACCD;">MAINTAINER  itheima </span><span style="color:#89DDFF;">&lt;</span><span style="color:#A6ACCD;">itheima</span><span style="color:#89DDFF;">@</span><span style="color:#A6ACCD;">itcast</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">cn</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;">执行安装vim命令： </span></span>
<span class="line"><span style="color:#A6ACCD;">RUN yum install </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">y vim</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;">定义默认的工作目录：</span></span>
<span class="line"><span style="color:#A6ACCD;">WORKDIR </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">usr</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;">定义容器启动执行的命令：</span></span>
<span class="line"><span style="color:#A6ACCD;">CMD </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;">构建执行</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;">通过dockerfile构建镜像：</span></span>
<span class="line"><span style="color:#A6ACCD;">docker bulid –f dockerfile文件路径 –t 镜像名称:版本</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;">构建：</span></span>
<span class="line"><span style="color:#A6ACCD;">docker build </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f </span><span style="color:#89DDFF;">./</span><span style="color:#A6ACCD;">cent_dockerfile </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">t centos:latest </span><span style="color:#89DDFF;">.</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;">执行：</span></span>
<span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">a1 centos:latest</span></span></code></pre></div><p>可以发现，vim可以使用了，而且定位在了usr目录</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005181514161.png" alt="image-20211005181514161" style="zoom:67%;"><h3 id="发布springboot项目" tabindex="-1">发布springboot项目 <a class="header-anchor" href="#发布springboot项目" aria-label="Permalink to &quot;发布springboot项目&quot;">​</a></h3><p>首先：将一个maven/SpringBoot项目进行打包</p><p>双击package进行打包</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005182215049.png" alt="image-20211005182215049" style="zoom:67%;"><p>在输出位置查看打包完成的jar包</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005182241476.png" alt="image-20211005182241476" style="zoom:80%;"><p>运行打包后的SpringBoot项目</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">java -jar .\springboot-hello-0.0.1-SNAPSHOT.jar</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005181955565.png" alt="image-20211005181955565" style="zoom:67%;"><p>运行成功后：访问地址生效</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005182038704.png" alt="image-20211005182038704" style="zoom:67%;"><p>将文件从win10传到linux</p><p>创建文件夹，将Dockerfile和demo-1.0jar都放在一个文件夹里</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mkdir dockerfileTest</span></span>
<span class="line"><span style="color:#A6ACCD;">mv demo</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">1.0</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">jar </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">dockerfileTest</span></span>
<span class="line"><span style="color:#A6ACCD;">cd </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">dockerfileTest</span></span>
<span class="line"><span style="color:#A6ACCD;">vim Dockerfile</span></span></code></pre></div><p>Dockerfile实现步骤</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">FROM java:</span><span style="color:#F78C6C;">8</span></span>
<span class="line"><span style="color:#A6ACCD;">MAINTAINER  itheima </span><span style="color:#89DDFF;">&lt;</span><span style="color:#A6ACCD;">itheima</span><span style="color:#89DDFF;">@</span><span style="color:#A6ACCD;">itcast</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">cn</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">ADD springboot</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">hello</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">0.0.1</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">SNAPSHOT</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">jar  app</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">jar</span></span>
<span class="line"><span style="color:#A6ACCD;">EXPOSE </span><span style="color:#F78C6C;">8080</span></span>
<span class="line"><span style="color:#A6ACCD;">ENTRYPOINT </span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">java</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">-jar</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">app.jar</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">]</span></span></code></pre></div><p>通过dockerfile构建镜像：docker bulid –f dockerfile文件路径 –t 镜像名称:版本</p><p>构建</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker build </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">t myspro:</span><span style="color:#F78C6C;">1.0</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">.</span></span></code></pre></div><p>运行</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">9001</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">8080</span><span style="color:#A6ACCD;"> myspro:</span><span style="color:#F78C6C;">1.0</span></span></code></pre></div><p>注意：执行完之后，要用docker ps -a，查看有没有端口映射成功。看PORTS</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005203300921.png" alt="image-20211005203300921" style="zoom:80%;"><p>访问</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005203054070.png" alt="image-20211005203054070" style="zoom:67%;"><h1 id="docker网络" tabindex="-1">Docker网络 <a class="header-anchor" href="#docker网络" aria-label="Permalink to &quot;Docker网络&quot;">​</a></h1><h2 id="是什么-1" tabindex="-1">是什么 <a class="header-anchor" href="#是什么-1" aria-label="Permalink to &quot;是什么&quot;">​</a></h2><p>docker不启动，默认网络情况</p><ul><li>ens33</li><li>Io</li><li>virbr0</li></ul><p>docker启动后，网络情况：会产生一个名为docker0的虚拟网桥</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210160614517.png" alt="image-20220210160614517" style="zoom:67%;"><p>查看docker网络模式命令</p><p>默认创建3大网络模式</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker network ls</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210160731025.png" alt="image-20220210160731025" style="zoom:67%;"><h2 id="常用基本命令" tabindex="-1">常用基本命令 <a class="header-anchor" href="#常用基本命令" aria-label="Permalink to &quot;常用基本命令&quot;">​</a></h2><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker network --help</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210163411130.png" alt="image-20220210163411130" style="zoom:67%;"><h4 id="创建网络" tabindex="-1">创建网络 <a class="header-anchor" href="#创建网络" aria-label="Permalink to &quot;创建网络&quot;">​</a></h4><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker network create 网络名称</span></span></code></pre></div><h4 id="查看网络" tabindex="-1">查看网络 <a class="header-anchor" href="#查看网络" aria-label="Permalink to &quot;查看网络&quot;">​</a></h4><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker network ls</span></span></code></pre></div><h4 id="查看网络源数据" tabindex="-1">查看网络源数据 <a class="header-anchor" href="#查看网络源数据" aria-label="Permalink to &quot;查看网络源数据&quot;">​</a></h4><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker network inspect XXX网络名字</span></span>
<span class="line"><span style="color:#A6ACCD;">docker network inspect host</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210163736999.png" alt="image-20220210163736999" style="zoom:50%;"><h4 id="删除网络" tabindex="-1">删除网络 <a class="header-anchor" href="#删除网络" aria-label="Permalink to &quot;删除网络&quot;">​</a></h4><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker network rm XXX网络名字</span></span></code></pre></div><p>示例</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker network create aa_network</span></span>
<span class="line"><span style="color:#A6ACCD;">docker network ls</span></span>
<span class="line"><span style="color:#A6ACCD;">docker network rm aa_network</span></span>
<span class="line"><span style="color:#A6ACCD;">docker network ls</span></span></code></pre></div><h3 id="能干嘛" tabindex="-1">能干嘛 <a class="header-anchor" href="#能干嘛" aria-label="Permalink to &quot;能干嘛&quot;">​</a></h3><ul><li>容器间的互联和通信以及端口映射</li><li>容器IP变动时候可以通过服务名直接网络通信而不受到影响</li></ul><h2 id="网络模式" tabindex="-1">网络模式 <a class="header-anchor" href="#网络模式" aria-label="Permalink to &quot;网络模式&quot;">​</a></h2><h3 id="总体介绍" tabindex="-1">总体介绍 <a class="header-anchor" href="#总体介绍" aria-label="Permalink to &quot;总体介绍&quot;">​</a></h3><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210174409094.png" alt="image-20220210174409094" style="zoom:67%;"><ul><li>bridge模式：使用--network bridge指定，默认使用docker0</li><li>host模式：使用--network host指定</li><li>none模式：使用--network none指定</li><li>container模式：使用--network container:NAME或者容器ID指定</li></ul><h3 id="演示示例" tabindex="-1">演示示例 <a class="header-anchor" href="#演示示例" aria-label="Permalink to &quot;演示示例&quot;">​</a></h3><p>结论：docker容器内部的ip是有可能会发生改变的</p><p>1 先启动两个ubuntu容器实例</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run -it --name u1 ubuntu bash</span></span>
<span class="line"><span style="color:#A6ACCD;">docker run -it --name u2 ubuntu bash</span></span></code></pre></div><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker ps</span></span></code></pre></div><p>2 docker inspect 容器ID or 容器名字</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker inspect u1 | tail -n 20</span></span>
<span class="line"><span style="color:#A6ACCD;">docker inspect u2 | tail -n 20</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210181643001.png" alt="image-20220210181643001" style="zoom:50%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210181739851.png" alt="image-20220210181739851" style="zoom:50%;"><p>3 关闭u2实例，新建u3，查看ip变化</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run -it --name u3 ubuntu bash</span></span>
<span class="line"><span style="color:#A6ACCD;">docker inspect u3 | tail -n 20</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220210182334782.png" alt="image-20220210182334782" style="zoom:50%;"><p>docker容器内部的ip是有可能会发生改变的</p><h4 id="bridge" tabindex="-1">bridge <a class="header-anchor" href="#bridge" aria-label="Permalink to &quot;bridge&quot;">​</a></h4><h5 id="是什么-2" tabindex="-1">是什么 <a class="header-anchor" href="#是什么-2" aria-label="Permalink to &quot;是什么&quot;">​</a></h5><p>Docker 服务默认会创建一个 docker0 网桥（其上有一个 docker0 内部接口），该桥接网络的名称为docker0，它在内核层连通了其他的物理或虚拟网卡，这<strong>就将所有容器和本地主机都放到同一个物理网络</strong>。Docker 默认指定了 docker0 接口 的 IP 地址和子网掩码，<strong>让主机和容器之间可以通过网桥相互通信</strong>。</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># 查看 bridge 网络的详细信息，并通过 grep 获取名称项</span></span>
<span class="line"><span style="color:#A6ACCD;">docker network inspect bridge | grep name</span></span></code></pre></div><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">ifconfig | grep docker</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220212100619947.png" alt="image-20220212100619947" style="zoom:67%;"><p>相当于Vmware中的 nat 模式，容器使用独立<code>network Namespace</code>，并连接到docker0虚拟网卡。通过docker0网桥以及<code>iptables nat</code>表配置与宿主机通信，此模式会为每一个容器分配<code>Network Namespace</code>、设置IP等，并将一个主机上的 Docker 容器连接到一个虚拟网桥上。</p><p>当Docker进程启动时，会在主机上创建一个名为docker0的虚拟网桥，此主机上启动的Docker容器会连接到这个虚拟网桥上。虚拟网桥的工作方式和物理交换机类似，这样主机上的所有容器就通过交换机连在了一个二层网络中。</p><p>从docker0子网中分配一个IP给容器使用，并设置docker0的IP地址为容器的默认网关。在主机上创建一对虚拟网卡<code>veth pair</code>设备。veth设备总是成对出现的，它们组成了一个数据的通道，数据从一个设备进入，就会从另一个设备出来。因此，veth设备常用来连接两个网络设备。</p><p>Docker将<code>veth pair</code> 设备的一端放在新创建的容器中，并命名为eth0（容器的网卡），另一端放在主机中， 以<code>veth*</code>这样类似的名字命名，并将这个网络设备加入到docker0网桥中。可以通过 <code>brctl show</code> 命令查看。</p><p>容器之间通过<code>veth pair</code>进行访问</p><p>使用 <code>docker run -p</code> 时，docker实际是在iptables做了DNAT规则，实现端口转发功能。</p><p>可以使用<code>iptables -t nat -vnL</code> 查看。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.12.30/202210291857905.png" alt="image-20221029185722793" style="zoom:67%;"><h5 id="说明" tabindex="-1">说明 <a class="header-anchor" href="#说明" aria-label="Permalink to &quot;说明&quot;">​</a></h5><p>Docker使用Linux桥接，在宿主机虚拟一个Docker容器网桥(docker0)，Docker启动一个容器时会根据Docker网桥的网段分配给容器一个IP地址，称为Container-IP，同时Docker网桥是每个容器的默认网关。因为在同一宿主机内的容器都接入同一个网桥，这样容器之间就能够通过容器的Container-IP直接通信。</p><p>docker run 的时候，没有指定network的话默认使用的网桥模式就是bridge，使用的就是docker0。在宿主机ifconfig,就可以看到docker0和自己create的network(后面讲)eth0，eth1，eth2……代表网卡一，网卡二，网卡三……，lo代表127.0.0.1，即localhost，inet addr用来表示网卡的IP地址</p><p>网桥docker0创建一对对等虚拟设备接口一个叫veth，另一个叫eth0，成对匹配。 整个宿主机的网桥模式都是docker0，类似一个交换机有一堆接口，每个接口叫veth，在本地主机和容器内分别创建一个虚拟接口，并让他们彼此联通（这样一对接口叫veth pair）；</p><p>每个容器实例内部也有一块网卡，每个接口叫eth0；docker0上面的每个veth匹配某个容器实例内部的eth0，两两配对，一一匹配。通过上述，将宿主机上的所有容器都连接到这个内部网络上，两个容器在同一个网络下,会从这个网关下各自拿到分配的ip，此时两个容器的网络是互通的。</p><h4 id="host" tabindex="-1">host <a class="header-anchor" href="#host" aria-label="Permalink to &quot;host&quot;">​</a></h4><h5 id="说明-1" tabindex="-1">说明 <a class="header-anchor" href="#说明-1" aria-label="Permalink to &quot;说明&quot;">​</a></h5><p><strong>直接使用宿主机的 IP 地址与外界进行通信</strong>，不再需要额外进行NAT 转换</p><p>容器将<strong>不会获得一个独立的Network Namespace</strong>， 而是和宿主机共用一个Network Namespace。<strong>容器将不会虚拟出自己的网卡而是使用宿主机的IP和端口</strong>。</p><h5 id="代码示例" tabindex="-1">代码示例 <a class="header-anchor" href="#代码示例" aria-label="Permalink to &quot;代码示例&quot;">​</a></h5><p>警告</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run -d -p 8083:8080 --network host --name tomcat83 billygoo/tomcat8-jdk8</span></span></code></pre></div><p>问题：启动命令时总是遇见标题中的警告</p><p>原因：Docker启动时指定--network=host或-net=host，如果还指定了-p映射端口，那这个时候就会有此警告， <strong>并且通过-p设置的参数将不会起到任何作用</strong>，端口号会以主机端口号为主，重复时则递增。 解决:解决的办法就是使用docker的其他网络模式，例如--network=bridge，这样就可以解决问题，或者直接无视。。。。O(∩_∩)O哈哈~</p><p>正确</p><p>不加端口号</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d  </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">network host </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name tomcat83 billygoo</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">tomcat8</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">jdk8</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker inspect tomcat83 </span><span style="color:#89DDFF;">|</span><span style="color:#A6ACCD;"> tail </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">n </span><span style="color:#F78C6C;">20</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220214215912777.png" alt="image-20220214215912777" style="zoom:67%;"><p>没有设置-p的端口映射了，如何访问启动的tomcat83？？</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">http://192.168.220.130:8080/</span></span></code></pre></div><p>在CentOS里面用默认的火狐浏览器访问容器内的tomcat83看到访问成功，因为<strong>此时容器的IP借用主机</strong>的， <strong>所以容器共享宿主机网络IP，这样的好处是外部主机与容器可以直接通信</strong>。</p><h4 id="none" tabindex="-1">none <a class="header-anchor" href="#none" aria-label="Permalink to &quot;none&quot;">​</a></h4><p>禁用网络功能，只有lo标识(就是127.0.0.1表示本地回环)</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">8084</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">8080</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">network none </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name tomcat84 billygoo</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">tomcat8</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">jdk8</span></span></code></pre></div><p>外部网络无法访问，内部网络也无法访问</p><p>none模式:使用 <code>--net=none</code>指定</p><p>使用none 模式，docker 容器有自己的<code>network Namespace</code> ，但是并不为Docker 容器进行任何网络配置。也就是说，这个Docker 容器没有网卡，ip， 路由等信息。这种网络模式下，容器只有lo 回环网络，没有其他网卡。这种类型没有办法联网，但是封闭的网络能很好的保证容器的安全性。该容器将完全独立于网络，用户可以根据需要为容器添加网卡。此模式拥有所有端口。（none网络模式配置网络）特殊情况下才会用到，一般不用</p><h4 id="container" tabindex="-1">container <a class="header-anchor" href="#container" aria-label="Permalink to &quot;container&quot;">​</a></h4><h5 id="是什么-3" tabindex="-1">是什么 <a class="header-anchor" href="#是什么-3" aria-label="Permalink to &quot;是什么&quot;">​</a></h5><p>新建的容器和已经存在的一个容器共享一个网络ip配置而不是和宿主机共享。新创建的容器不会创建自己的网卡，配置自己的IP，而是和一个指定的容器共享IP、端口范围等。同样，两个容器除了网络方面，其他的如文件系统、进程列表等还是隔离的。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220212102750565.png" alt="image-20220212102750565" style="zoom:67%;"><p>container模式：使用<code>–net=contatiner:NAME_or_ID </code>指定</p><p>这个模式指定新创建的容器和已经存在的一个容器共享一个<code>Network Namespace</code>，而不是和宿主机共享。<strong>新创建的容器不会创建自己的网卡，配置自己的IP，而是和一个指定的容器共享IP，端口范围等。</strong> 可以在一定程度上节省网络资源，容器内部依然不会拥有所有端口。</p><p>同样，两个容器除了网络方面，其他的如文件系统，进程列表等还是隔离的。</p><p>两个容器的进程可以通过lo网卡设备通信</p><h4 id="自定义网络" tabindex="-1">自定义网络 <a class="header-anchor" href="#自定义网络" aria-label="Permalink to &quot;自定义网络&quot;">​</a></h4><h5 id="不使用自定义网络出现的问题" tabindex="-1">不使用自定义网络出现的问题 <a class="header-anchor" href="#不使用自定义网络出现的问题" aria-label="Permalink to &quot;不使用自定义网络出现的问题&quot;">​</a></h5><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run -d -p 8081:8080   --name tomcat81 billygoo/tomcat8-jdk8</span></span>
<span class="line"><span style="color:#A6ACCD;">docker run -d -p 8082:8080   --name tomcat82 billygoo/tomcat8-jdk8</span></span></code></pre></div><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec -it tomcat81 bash</span></span>
<span class="line"><span style="color:#A6ACCD;">ip addr</span></span>
<span class="line"><span style="color:#A6ACCD;">ping 172.17.0.2</span></span></code></pre></div><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec -it tomcat82 bash</span></span>
<span class="line"><span style="color:#A6ACCD;">ip addr</span></span>
<span class="line"><span style="color:#A6ACCD;">ping 172.17.0.3</span></span></code></pre></div><p>问题：ping服务名ping不通，比如ping tomcat81会报错，不认识该服务名</p><h5 id="使用自定义网络" tabindex="-1">使用自定义网络 <a class="header-anchor" href="#使用自定义网络" aria-label="Permalink to &quot;使用自定义网络&quot;">​</a></h5><p>自定义桥接网络,<strong>自定义网络默认使用的是桥接网络bridge</strong></p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker network create zzyy_network</span></span></code></pre></div><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run -d -p 8081:8080 --network zzyy_network  --name tomcat81 billygoo/tomcat8-jdk8</span></span>
<span class="line"><span style="color:#A6ACCD;">docker run -d -p 8082:8080 --network zzyy_network  --name tomcat82 billygoo/tomcat8-jdk8</span></span></code></pre></div><p>可以ping通服务名</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec -it tomcat82 bash</span></span>
<span class="line"><span style="color:#A6ACCD;">ping tomcat81</span></span></code></pre></div><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec -it tomcat81 bash</span></span>
<span class="line"><span style="color:#A6ACCD;">ping tomcat82</span></span></code></pre></div><p>结论：自定义网络本身就维护好了主机名和ip的对应关系（ip和域名都能通）</p><h1 id="docker-compose⭐" tabindex="-1">Docker Compose⭐ <a class="header-anchor" href="#docker-compose⭐" aria-label="Permalink to &quot;Docker Compose⭐&quot;">​</a></h1><p>Compose 是 Docker 公司推出的一个工具软件，可以管理多个 Docker 容器组成一个应用。你需要定义一个 YAML 格式的配置文件docker-compose.yml，写好多个容器之间的调用关系。然后，只要一个命令，就能同时启动/关闭这些容器</p><blockquote><p>Docker Compose可以基于Compose文件帮我们快速的部署分布式应用，而无需手动一个个创建和运行容器！</p></blockquote><p>DockerCompose的详细语法参考官网：<a href="https://docs.docker.com/compose/compose-file/" target="_blank" rel="noreferrer">https://docs.docker.com/compose/compose-file/</a></p><p>其实DockerCompose文件可以看做是将多个docker run命令写到一个文件，只是语法稍有差异。</p><h2 id="常用命令-1" tabindex="-1">常用命令 <a class="header-anchor" href="#常用命令-1" aria-label="Permalink to &quot;常用命令&quot;">​</a></h2><ul><li>docker-compose -h # 查看帮助</li><li>docker-compose up # 启动所有docker-compose服务</li><li>docker-compose up -d # 启动所有docker-compose服务并后台运行</li><li>docker-compose down # 停止并删除容器、网络、卷、镜像。</li><li>docker-compose exec yml里面的服务id # 进入容器实例内部 docker-compose exec docker-compose.yml文件中写的服务id /bin/bash</li><li>docker-compose ps # 展示当前docker-compose编排过的运行的所有容器</li><li>docker-compose top # 展示当前docker-compose编排过的容器进程</li><li>docker-compose logs yml里面的服务id # 查看容器输出日志</li><li>dokcer-compose config # 检查配置</li><li>docker-compose config -q # 检查配置，有问题才有输出</li><li>docker-compose restart # 重启服务</li><li>docker-compose start # 启动服务</li><li>docker-compose stop # 停止服务</li></ul><p>注意：使用这些命令时需要在docker-compose.yml所在文件夹，不然不能生效，因为找不到文件</p><h2 id="改造springboot工程" tabindex="-1">改造SpringBoot工程 <a class="header-anchor" href="#改造springboot工程" aria-label="Permalink to &quot;改造SpringBoot工程&quot;">​</a></h2><p>SpringBoot项目使用了mysql和redis，在SpringBoot笔记中记录了详细内容</p><h3 id="不用compose" tabindex="-1">不用compose <a class="header-anchor" href="#不用compose" aria-label="Permalink to &quot;不用compose&quot;">​</a></h3><h4 id="mysql配置" tabindex="-1">mysql配置 <a class="header-anchor" href="#mysql配置" aria-label="Permalink to &quot;mysql配置&quot;">​</a></h4><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">3307</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">3306</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">privileged</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">true </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">log:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">log</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">conf:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">conf</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">e MYSQL_ROOT_PASSWORD</span><span style="color:#89DDFF;">=</span><span style="color:#F78C6C;">123456</span><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name mysql5</span><span style="color:#F78C6C;">.7</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql</span><span style="color:#89DDFF;">:</span><span style="color:#F78C6C;">5.7</span></span></code></pre></div><p>至于修改中文编码情况见前面的部署MySQL部分</p><p>进入数据库，插入数据</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it mysql5</span><span style="color:#F78C6C;">.7</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">uroot </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p123456</span></span></code></pre></div><p>建议使用远程连接方式创建表和插入数据，因为linux不能输入中文</p><div class="language-mysql"><button title="Copy Code" class="copy"></button><span class="lang">mysql</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">CREATE TABLE `admin`  (</span></span>
<span class="line"><span style="color:#A6ACCD;">  `id` int(11) NOT NULL AUTO_INCREMENT,</span></span>
<span class="line"><span style="color:#A6ACCD;">  `username` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,</span></span>
<span class="line"><span style="color:#A6ACCD;">  `password` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,</span></span>
<span class="line"><span style="color:#A6ACCD;">  PRIMARY KEY (`id`) USING BTREE</span></span>
<span class="line"><span style="color:#A6ACCD;">) ENGINE = InnoDB AUTO_INCREMENT = 18 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;</span></span>
<span class="line"><span style="color:#A6ACCD;"></span></span>
<span class="line"><span style="color:#A6ACCD;">INSERT INTO `admin` VALUES (4, &#39;张三&#39;, &#39;4321&#39;);</span></span>
<span class="line"><span style="color:#A6ACCD;">INSERT INTO `admin` VALUES (5, &#39;李四&#39;, &#39;21321&#39;);</span></span>
<span class="line"><span style="color:#A6ACCD;">INSERT INTO `admin` VALUES (6, &#39;曹操&#39;, &#39;123124&#39;);</span></span>
<span class="line"><span style="color:#A6ACCD;">INSERT INTO `admin` VALUES (7, &#39;刘备&#39;, &#39;12132&#39;);</span></span>
<span class="line"><span style="color:#A6ACCD;">INSERT INTO `admin` VALUES (8, &#39;曹猛地&#39;, &#39;123124&#39;);</span></span></code></pre></div><h4 id="redis配置" tabindex="-1">redis配置 <a class="header-anchor" href="#redis配置" aria-label="Permalink to &quot;redis配置&quot;">​</a></h4><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run  </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">6379</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">6379</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name myr3 </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">privileged</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">true </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">conf:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">conf </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">DockerData</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d redis:</span><span style="color:#F78C6C;">6.0.8</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">server </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">etc</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">conf</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker exec </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">it myr3 </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bin</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">bash</span></span>
<span class="line"><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">cli</span></span>
<span class="line"><span style="color:#A6ACCD;">keys </span><span style="color:#89DDFF;">*</span></span>
<span class="line"><span style="color:#A6ACCD;">get user:</span><span style="color:#F78C6C;">4</span></span></code></pre></div><p>为避免出错，需要在redis.conf中配置，<strong>因为远程连接要是设置保护模式就会出错</strong></p><p>方法一：<strong>把protected-mode yes修改成protected-mode no，然后重启服务器即可</strong></p><p>方法二：设置bind的地址和Redis密码。这种方式是在正式、联网环境可以安全使用的方法。（requirepass 的密码建议要复杂一些，否则不安全，我这里是内网环境所以用的比较简单）</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">bind </span><span style="color:#F78C6C;">192.168.220.130</span></span>
<span class="line"><span style="color:#A6ACCD;">requirepass </span><span style="color:#F78C6C;">123456</span></span></code></pre></div><p>在win10CMD中进行查询</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">redis</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">cli </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">h </span><span style="color:#F78C6C;">192.168.220.130</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">6379</span></span></code></pre></div><h4 id="微服务工程将打包好的jar包上传后-编写dockerfile" tabindex="-1">微服务工程将打包好的jar包上传后，编写Dockerfile <a class="header-anchor" href="#微服务工程将打包好的jar包上传后-编写dockerfile" aria-label="Permalink to &quot;微服务工程将打包好的jar包上传后，编写Dockerfile&quot;">​</a></h4><p>创建文件夹，将Dockerfile和demo-1.0jar都放在一个文件夹里</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mkdir dockerfileTest</span></span>
<span class="line"><span style="color:#A6ACCD;">mv demo-1.0.jar /dockerfileTest</span></span>
<span class="line"><span style="color:#A6ACCD;">cd /dockerfileTest</span></span>
<span class="line"><span style="color:#A6ACCD;">vim Dockerfile</span></span></code></pre></div><p>Dockerfile实现步骤</p><div class="language-dockerfile"><button title="Copy Code" class="copy"></button><span class="lang">dockerfile</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F78C6C;">FROM</span><span style="color:#A6ACCD;"> java:8</span></span>
<span class="line"><span style="color:#F78C6C;">MAINTAINER</span><span style="color:#A6ACCD;">  itheima &lt;itheima@itcast.cn&gt;</span></span>
<span class="line"><span style="color:#F78C6C;">ADD</span><span style="color:#A6ACCD;"> springboot-hello-0.0.1-SNAPSHOT.jar  app.jar</span></span>
<span class="line"><span style="color:#F78C6C;">EXPOSE</span><span style="color:#A6ACCD;"> 8080</span></span>
<span class="line"><span style="color:#F78C6C;">ENTRYPOINT</span><span style="color:#A6ACCD;"> [</span><span style="color:#C3E88D;">&quot;java&quot;</span><span style="color:#A6ACCD;">,</span><span style="color:#C3E88D;">&quot;-jar&quot;</span><span style="color:#A6ACCD;">,</span><span style="color:#C3E88D;">&quot;app.jar&quot;</span><span style="color:#A6ACCD;">]</span></span></code></pre></div><p>通过dockerfile构建镜像：docker bulid –f dockerfile文件路径 –t 镜像名称:版本</p><p>构建</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker build -t myspro:1.0 .</span></span></code></pre></div><p>运行</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run -d -p 9001:8080 myspro:1.0</span></span></code></pre></div><p>注意：执行完之后，要用docker ps -a，查看有没有端口映射成功。看PORTS</p><p>上面三个容器实例依次顺序启动成功</p><p>进入访问</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">http://192.168.220.130:9001/swagger-ui.html#/</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220212150940971.png" alt="image-20220212150940971" style="zoom:67%;"><p>依次测试方法，应该都能成功</p><p>上面成功了，有哪些问题?</p><ul><li>先后顺序要求固定，先mysql+redis才能微服务访问成功</li><li>多个run命令......</li><li>容器间的启停或宕机，有可能导致IP地址对应的容器实例变化，映射出错，要么生产IP写死(可以但是不推荐)，要么通过服务调用</li></ul><h4 id="使用compose" tabindex="-1">使用compose <a class="header-anchor" href="#使用compose" aria-label="Permalink to &quot;使用compose&quot;">​</a></h4><p>docker-compose.yml</p><p>编写docker-compose.yml文件，注意内容要填写正确，container_name是自己定义的</p><div class="language-yml"><button title="Copy Code" class="copy"></button><span class="lang">yml</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F07178;">version</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">3</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#F07178;">services</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">microService</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">image</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">myspro:1.0</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">container_name</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">ms01</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">ports</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">9001:8080</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">volumes</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/app/microService:/data</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">networks</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">atguigu_net</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">depends_on</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">redis</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mysql</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">redis</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">image</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">redis:6.0.8</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">ports</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">6379:6379</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">volumes</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/DockerData/redis/redis.conf:/etc/redis/redis.conf</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/DockerData/redis/data:/data</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">networks</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">atguigu_net</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">command</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">redis-server /etc/redis/redis.conf</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">mysql</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">image</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mysql:5.7</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">environment</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#F07178;">MYSQL_ROOT_PASSWORD</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">123456</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#F07178;">MYSQL_ALLOW_EMPTY_PASSWORD</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">no</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#F07178;">MYSQL_DATABASE</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">girls</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#F07178;">MYSQL_USER</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">root</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#F07178;">MYSQL_PASSWORD</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">123456</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">ports</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">       </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">3307:3306</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">volumes</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">       </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/DockerData/mysql/log:/var/log/mysql</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">       </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/DockerData/mysql/data:/var/lib/mysql</span></span>
<span class="line"><span style="color:#A6ACCD;">       </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/DockerData/mysql/conf:/etc/mysql/conf.d</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">networks</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">atguigu_net</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">command</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--default-authentication-plugin=mysql_native_password</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;">#解决外部无法访问</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#F07178;">networks</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">   </span><span style="color:#F07178;">atguigu_net</span><span style="color:#89DDFF;">:</span></span></code></pre></div><p>注意：笔记上说要将application.yml的mysql和redis的host连接的ip地址分别换成mysql和redis，然而验证换了之后无法访问，<strong>还是不用换，保持原样即可</strong></p><p>执行</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">检查配置，有问题才有输出</span></span>
<span class="line"><span style="color:#A6ACCD;">dokcer-compose config -q  </span></span>
<span class="line"><span style="color:#A6ACCD;">然后执行 docker-compose up</span></span>
<span class="line"><span style="color:#A6ACCD;">或者</span></span>
<span class="line"><span style="color:#A6ACCD;">执行 docker-compose up -d</span></span></code></pre></div><p>关停</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker-compose stop</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220212163513537.png" alt="image-20220212163513537" style="zoom:80%;"><h2 id="nginx-springboot项目" tabindex="-1">nginx+springboot项目 <a class="header-anchor" href="#nginx-springboot项目" aria-label="Permalink to &quot;nginx+springboot项目&quot;">​</a></h2><p>最好创建在个人目录，这样容易修改</p><ol><li>创建docker-compose目录</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">mkdir</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/docker-compose</span></span>
<span class="line"><span style="color:#82AAFF;">cd</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/docker-compose</span></span></code></pre></div><ol start="2"><li>编写 docker-compose.yml 文件</li></ol><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">version:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">3</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#FFCB6B;">services:</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#FFCB6B;">nginx:</span></span>
<span class="line"><span style="color:#A6ACCD;">   </span><span style="color:#FFCB6B;">image:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx</span></span>
<span class="line"><span style="color:#A6ACCD;">   </span><span style="color:#FFCB6B;">ports:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">80</span><span style="color:#C3E88D;">:80</span></span>
<span class="line"><span style="color:#A6ACCD;">   </span><span style="color:#FFCB6B;">links:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">app</span></span>
<span class="line"><span style="color:#A6ACCD;">   </span><span style="color:#FFCB6B;">volumes:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">./nginx/conf.d:/etc/nginx/conf.d</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#FFCB6B;">app:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">image:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">app</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">expose:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#FFCB6B;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">8080</span><span style="color:#89DDFF;">&quot;</span></span></code></pre></div><p>创建./nginx/conf.d目录</p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">mkdir</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">./nginx/conf.d</span></span>
<span class="line"><span style="color:#82AAFF;">cd</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">./nginx/conf.d</span></span></code></pre></div><p>在./nginx/conf.d目录下 编写itheima.conf文件</p><p>注意： <a href="http://app:8080" target="_blank" rel="noreferrer">http://app:8080</a>;这里的app对应的是links的app</p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">server</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">{</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">listen</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">80</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">access_log</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">off</span><span style="color:#89DDFF;">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#FFCB6B;">location</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">{</span></span>
<span class="line"><span style="color:#A6ACCD;">        </span><span style="color:#FFCB6B;">proxy_pass</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">http://app:8080</span><span style="color:#89DDFF;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">    }</span></span>
<span class="line"><span style="color:#A6ACCD;">   </span></span>
<span class="line"><span style="color:#A6ACCD;">}</span></span></code></pre></div><p>在~/docker-compose 目录下 使用docker-compose 启动容器</p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker-compose</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">up</span></span></code></pre></div><p>运行成功页面</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005210851644.png" alt="image-20211005210851644" style="zoom:80%;"><p>测试访问</p><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">http://192.168.220.128/hello</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20211005210759990.png" alt="image-20211005210759990" style="zoom:67%;"><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run -d -p 3307:3306 --privileged=true \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v /DockerData/mysql/log:/var/log/mysql \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v /DockerData/mysql/data:/var/lib/mysql \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v /DockerData/mysql/conf:/etc/mysql/conf.d \</span></span>
<span class="line"><span style="color:#A6ACCD;">-e MYSQL_ROOT_PASSWORD=123456  \</span></span>
<span class="line"><span style="color:#A6ACCD;">--name mysql5.7 \</span></span>
<span class="line"><span style="color:#A6ACCD;">mysql:5.7</span></span></code></pre></div><h2 id="部署微服务⭐" tabindex="-1">部署微服务⭐ <a class="header-anchor" href="#部署微服务⭐" aria-label="Permalink to &quot;部署微服务⭐&quot;">​</a></h2><p>查看课前资料提供的cloud-demo文件夹，里面已经编写好了docker-compose文件，而且每个微服务都准备了一个独立的目录：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011217374.png" alt="image-20210731181341330" style="zoom:67%;"><p>内容如下：</p><div class="language-yaml"><button title="Copy Code" class="copy"></button><span class="lang">yaml</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F07178;">version</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">3.2</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F07178;">services</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">nacos</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">image</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nacos/nacos-server</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">environment</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#F07178;">MODE</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">standalone</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">ports</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">8848:8848</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">mysql</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">image</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mysql:5.7.25</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">environment</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#F07178;">MYSQL_ROOT_PASSWORD</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">123</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">volumes</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">$PWD/mysql/data:/var/lib/mysql</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">$PWD/mysql/conf:/etc/mysql/conf.d/</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">userservice</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">build</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">./user-service</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">orderservice</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">build</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">./order-service</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">gateway</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">build</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">./gateway</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">ports</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">10010:10010</span><span style="color:#89DDFF;">&quot;</span></span></code></pre></div><p>可以看到，其中包含5个service服务：</p><p><code>nacos</code>：作为注册中心和配置中心</p><ul><li><code>image: nacos/nacos-server</code>： 基于nacos/nacos-server镜像构建</li><li><code>environment</code>：环境变量 <ul><li><code>MODE: standalone</code>：单点模式启动</li><li><code>ports</code>：端口映射，这里暴露了8848端口</li></ul></li></ul><p><code>mysql</code>：数据库</p><ul><li><code>image: mysql:5.7.25</code>：镜像版本是mysql:5.7.25</li><li><code>environment</code>：环境变量 <ul><li><code>MYSQL_ROOT_PASSWORD: 123</code>：设置数据库root账户的密码为123</li></ul></li><li><code>volumes</code>：数据卷挂载，这里挂载了mysql的data、conf目录，其中有我提前准备好的数据</li></ul><p><code>userservice</code>、<code>orderservice</code>、<code>gateway</code>：都是基于Dockerfile临时构建的</p><p>查看mysql目录，可以看到其中已经准备好了cloud_order、cloud_user表：</p><p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011217379.png" alt="image-20210801095205034"></p><p>查看微服务目录，可以看到都包含Dockerfile文件：</p><p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011217382.png" alt="image-20210801095320586">内容如下：</p><div class="language-dockerfile"><button title="Copy Code" class="copy"></button><span class="lang">dockerfile</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F78C6C;">FROM</span><span style="color:#A6ACCD;"> java:8-alpine</span></span>
<span class="line"><span style="color:#F78C6C;">COPY</span><span style="color:#A6ACCD;"> ./app.jar /tmp/app.jar</span></span>
<span class="line"><span style="color:#F78C6C;">ENTRYPOINT</span><span style="color:#A6ACCD;"> java -jar /tmp/app.jar</span></span></code></pre></div><p>修改微服务配置</p><p>因为微服务将来要部署为docker容器，而容器之间互联不是通过IP地址，而是通过容器名。这里我们将order-service、user-service、gateway服务的mysql、nacos地址都修改为基于容器名的访问。</p><p>如下所示：</p><div class="language-yaml"><button title="Copy Code" class="copy"></button><span class="lang">yaml</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F07178;">spring</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">datasource</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#89DDFF;">    </span><span style="color:#676E95;font-style:italic;"># 这里直接改成服务名mysql，而不是localhost</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">url</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">jdbc:mysql://mysql:3306/cloud_order?useSSL=false</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">username</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">root</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">password</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">123</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">driver-class-name</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">com.mysql.jdbc.Driver</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">application</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">name</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">orderservice</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">cloud</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">nacos</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#89DDFF;">      </span><span style="color:#676E95;font-style:italic;"># 这里也直接改成服务名nacos，而不是localhost</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#F07178;">server-addr</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nacos:8848</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;"># nacos服务地址</span></span></code></pre></div><h3 id="打包" tabindex="-1">打包 <a class="header-anchor" href="#打包" aria-label="Permalink to &quot;打包&quot;">​</a></h3><p>接下来需要将我们的每个微服务都打包。因为之前查看到Dockerfile中的jar包名称都是app.jar，因此我们的每个微服务都需要用这个名称。</p><p>可以通过修改pom.xml中的打包名称来实现，每个微服务都需要修改：</p><div class="language-xml"><button title="Copy Code" class="copy"></button><span class="lang">xml</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">build</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#676E95;font-style:italic;">&lt;!-- 服务打包的最终名称 --&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">finalName</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">app</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">finalName</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">plugins</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">plugin</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">org.springframework.boot</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">groupId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">&lt;</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span><span style="color:#A6ACCD;">spring-boot-maven-plugin</span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">artifactId</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">plugin</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">plugins</span><span style="color:#89DDFF;">&gt;</span></span>
<span class="line"><span style="color:#89DDFF;">&lt;/</span><span style="color:#F07178;">build</span><span style="color:#89DDFF;">&gt;</span></span></code></pre></div><p>打包后：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011222533.png" alt="image-20210801095951030" style="zoom:50%;"><h3 id="拷贝jar包到部署目录" tabindex="-1">拷贝jar包到部署目录 <a class="header-anchor" href="#拷贝jar包到部署目录" aria-label="Permalink to &quot;拷贝jar包到部署目录&quot;">​</a></h3><p>编译打包好的app.jar文件，需要放到Dockerfile的同级目录中。注意：每个微服务的app.jar放到与服务名称对应的目录，别搞错了。</p><p>user-service：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011222536.png" alt="image-20210801100201253" style="zoom:50%;"><p>order-service：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011222536.png" alt="image-20210801100231495" style="zoom:50%;"><p>gateway：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011222537.png" alt="image-20210801100308102" style="zoom:50%;"><h3 id="部署" tabindex="-1">部署 <a class="header-anchor" href="#部署" aria-label="Permalink to &quot;部署&quot;">​</a></h3><p>最后，我们需要将文件整个cloud-demo文件夹上传到虚拟机中，理由DockerCompose部署。</p><p>上传到任意目录：</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011222543.png" alt="image-20210801100955653" style="zoom:50%;"><p>部署：</p><p>进入cloud-demo目录，然后运行下面的命令：</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker-compose</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">up</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-d</span></span></code></pre></div><h1 id="私有仓库" tabindex="-1">私有仓库 <a class="header-anchor" href="#私有仓库" aria-label="Permalink to &quot;私有仓库&quot;">​</a></h1><blockquote><p>Docker官方的Docker hub（<a href="https://hub.docker.com" target="_blank" rel="noreferrer">https://hub.docker.com</a>）是一个用于管理公共镜像的仓库，我们可以从上面拉取镜像 到本地，也可以把我们自己的镜像推送上去。但是，有时候我们的服务器无法访问互联网，或者你不希望将自己的镜 像放到公网当中，就需要搭建私有仓库来存储和管理自己的镜像</p></blockquote><h2 id="简化版镜像仓库" tabindex="-1">简化版镜像仓库 <a class="header-anchor" href="#简化版镜像仓库" aria-label="Permalink to &quot;简化版镜像仓库&quot;">​</a></h2><blockquote><p>Docker官方的Docker Registry是一个基础版本的Docker镜像仓库，具备仓库管理的完整功能，但是没有图形化界面。搭建方式比较简单，命令如下：</p></blockquote><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-d</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#C3E88D;">--restart=always</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#C3E88D;">--name</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">registry</span><span style="color:#A6ACCD;">	\</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">5000</span><span style="color:#C3E88D;">:5000</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#C3E88D;">-v</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">registry-data:/var/lib/registry</span><span style="color:#A6ACCD;"> \</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#C3E88D;">registry</span></span></code></pre></div><blockquote><p>命令中挂载了一个数据卷registry-data到容器内的/var/lib/registry 目录，这是私有镜像库存放数据的目录。访问<a href="http://YourIp:5000/v2/_catalog" target="_blank" rel="noreferrer">http://YourIp:5000/v2/_catalog</a> 可以查看当前私有镜像服务中包含的镜像</p></blockquote><h2 id="带有图形化界面版本⭐" tabindex="-1">带有图形化界面版本⭐ <a class="header-anchor" href="#带有图形化界面版本⭐" aria-label="Permalink to &quot;带有图形化界面版本⭐&quot;">​</a></h2><p>使用DockerCompose部署带有图象界面的DockerRegistry，命令如下：</p><p>5000是内部端口，我无法访问，所以访问暴露的8080端口即可</p><div class="language-yaml"><button title="Copy Code" class="copy"></button><span class="lang">yaml</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F07178;">version</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">3.0</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#F07178;">services</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">registry</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">image</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">registry</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">volumes</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">./registry-data:/var/lib/registry</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">ui</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">image</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">joxit/docker-registry-ui:static</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">ports</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">8080:80</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">environment</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">REGISTRY_TITLE=我的私有仓库</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">REGISTRY_URL=http://registry:5000</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">depends_on</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">registry</span></span></code></pre></div><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">compose up </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d</span></span></code></pre></div><p>访问：<a href="http://101.43.33.227:8080/" target="_blank" rel="noreferrer">http://101.43.33.227:8080/</a></p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011249843.png" alt="image-20220901124950696" style="zoom:67%;"><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 查看日志</span></span>
<span class="line"><span style="color:#A6ACCD;">docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">compose logs </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">f</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011251517.png" alt="image-20220901125108237" style="zoom:80%;"><h2 id="配置docker信任地址" tabindex="-1">配置Docker信任地址 <a class="header-anchor" href="#配置docker信任地址" aria-label="Permalink to &quot;配置Docker信任地址&quot;">​</a></h2><p>我们的私服采用的是http协议，默认不被Docker信任，所以需要做一个配置：</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 打开要修改的文件</span></span>
<span class="line"><span style="color:#FFCB6B;">vi</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/etc/docker/daemon.json</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 添加内容：</span></span>
<span class="line"><span style="color:#89DDFF;">{</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#FFCB6B;">&quot;registry-mirrors&quot;</span><span style="color:#82AAFF;">:</span><span style="color:#A6ACCD;"> [</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">https://hi7nmgjd.mirror.aliyuncs.com</span><span style="color:#89DDFF;">&quot;</span><span style="color:#A6ACCD;">],</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#FFCB6B;">&quot;insecure-registries&quot;</span><span style="color:#82AAFF;">:</span><span style="color:#A6ACCD;">[</span><span style="color:#FFCB6B;">&quot;10.0.16.16:8080&quot;</span><span style="color:#FFCB6B;">]</span></span>
<span class="line"><span style="color:#89DDFF;">}</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 重加载</span></span>
<span class="line"><span style="color:#FFCB6B;">systemctl</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">daemon-reload</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 重启docker</span></span>
<span class="line"><span style="color:#FFCB6B;">systemctl</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">restart</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">docker</span></span></code></pre></div><h2 id="将镜像上传至私有仓库" tabindex="-1">将镜像上传至私有仓库 <a class="header-anchor" href="#将镜像上传至私有仓库" aria-label="Permalink to &quot;将镜像上传至私有仓库&quot;">​</a></h2><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 1、标记镜像为私有仓库的镜像     </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">tag</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">centos:7</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">私有仓库服务器IP:5000/centos:7</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">tag</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx:latest</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">10.0</span><span style="color:#C3E88D;">.16.16:8080/nginx:1.0</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 2、上传标记的镜像     </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">push</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">私有仓库服务器IP:5000/centos:7</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">push</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">10.0</span><span style="color:#C3E88D;">.16.16:8080/nginx:1.0</span></span></code></pre></div><p>查看镜像是否上传成功</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011255422.png" alt="image-20220901125506243" style="zoom:67%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011255993.png" alt="image-20220901125518840" style="zoom:50%;"><h2 id="从私有仓库拉取镜像" tabindex="-1">从私有仓库拉取镜像 <a class="header-anchor" href="#从私有仓库拉取镜像" aria-label="Permalink to &quot;从私有仓库拉取镜像&quot;">​</a></h2><div class="language-shell"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 删除镜像</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">rmi</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">10.0</span><span style="color:#C3E88D;">.16.16:8080/nginx:1.0</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 拉取镜像 </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">pull</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">私有仓库服务器ip:5000/centos:7</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">pull</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">10.0</span><span style="color:#C3E88D;">.16.16:8080/nginx:1.0</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 运行</span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-it</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">镜像ID</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/bin/bash</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.8.30/202209011257666.png" alt="image-20220901125724523" style="zoom:80%;"><h1 id="可视化工具" tabindex="-1">可视化工具 <a class="header-anchor" href="#可视化工具" aria-label="Permalink to &quot;可视化工具&quot;">​</a></h1><h2 id="portainer轻量级" tabindex="-1">Portainer轻量级 <a class="header-anchor" href="#portainer轻量级" aria-label="Permalink to &quot;Portainer轻量级&quot;">​</a></h2><p>是一款轻量级的应用，它提供了图形化界面，用于方便地管理Docker环境，包括单机环境和集群环境。</p><p>Portainer 是一个轻量级的 WEB 管理 UI ，可让你轻松管理运行在 Docker、Swarm、Kubernetes 环境下的容器。Portainer 提供状态显示面板、应用模板快速部署、容器镜像网络数据卷的基本操作（包括上传下载镜像，创建容器等操作）、事件日志显示、容器控制台操作、Swarm 集群和服务等集中管理和操作、登录用户管理和控制等功能。功能十分全面，基本能满足中小型单位对容器管理的全部需求。全面支持 Linux、Mac OS、Windows 主流操作系统。</p><ul><li><a href="https://www.portainer.io/" target="_blank" rel="noreferrer">https://www.portainer.io/</a></li><li><a href="https://docs.portainer.io/v/ce-2.9/start/install/server/docker/linux" target="_blank" rel="noreferrer">https://docs.portainer.io/v/ce-2.9/start/install/server/docker/linux</a></li></ul><p>目前使用它来监控管理 Docker 容器，感觉它还是很强大的，非常好用。不足之处就是远程终端非常慢，不方便有时候远程进入容器内部进行操作。不过这不是拒绝它的理由，大部分日常都可以通过它很好的解决。</p><p>官方提供了<strong>Portainer 演示项目</strong>（账密：<em>admin</em> / <em>tryportainer</em>），如果有兴趣可以亲自感受一下。</p><blockquote><p><a href="http://demo.portainer.io/" target="_blank" rel="noreferrer">http://demo.portainer.io/</a></p></blockquote><h3 id="启动" tabindex="-1">启动 <a class="header-anchor" href="#启动" aria-label="Permalink to &quot;启动&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">d </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">8000</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">8000</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#F78C6C;">9000</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">9000</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">name portainer  </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">--</span><span style="color:#A6ACCD;">restart</span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">always  </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">run</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">docker</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">sock:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">run</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">docker</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">sock  </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">v portainer_data:</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">data     </span><span style="color:#89DDFF;">\</span></span>
<span class="line"><span style="color:#A6ACCD;">portainer</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">portainer</span></span></code></pre></div><h3 id="创建用户" tabindex="-1">创建用户 <a class="header-anchor" href="#创建用户" aria-label="Permalink to &quot;创建用户&quot;">​</a></h3><p>第一次登录要创建用户，用户名admin，密码自己设置8位：315217ren</p><p>对应选择local、要是远程就选择remote</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220213110521328.png" alt="image-20220213110521328" style="zoom:80%;"><p>点击进入，可以看到如下页面，对应docker命令</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker system df</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220213110655888.png" alt="image-20220213110655888" style="zoom:67%;"><p>侧边栏可以点击选择进入</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220213111746091.png" alt="image-20220213111746091" style="zoom:50%;"><h3 id="进入容器" tabindex="-1">进入容器 <a class="header-anchor" href="#进入容器" aria-label="Permalink to &quot;进入容器&quot;">​</a></h3><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220213112246768.png" alt="image-20220213112246768" style="zoom:67%;"><h3 id="创建容器" tabindex="-1">创建容器 <a class="header-anchor" href="#创建容器" aria-label="Permalink to &quot;创建容器&quot;">​</a></h3><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220213114130955.png" alt="image-20220213114130955" style="zoom:67%;"><p>创建完成即可</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220213115339928.png" alt="image-20220213115339928" style="zoom:67%;"><h2 id="dockstation" tabindex="-1">DockStation <a class="header-anchor" href="#dockstation" aria-label="Permalink to &quot;DockStation&quot;">​</a></h2><p>DockStation 是另一款 Docker 管理图形化界面，它比 Portainer 好的地方在于在多项目管理上非常清晰。</p><p><img src="https://mmbiz.qpic.cn/sz_mmbiz_png/zuF5sJGRDCvX6pokXVdicmFUuu8Xq1ib1V6ODo1EZ1SQQsm76H4eKia5aNt5jZMI89mqgzreh5OPc4hZ4FJ2xiaq0A/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><p>尤其能够图形化展示容器之间的依赖关系，尤其擅长管理 Docker-Compose，额外的它还支持监控统计、端口监视。而且 UI 设计的非常漂亮、非常清新，如果你希望对容器进行层次分明的管理的话不妨试一试它，它也支持 Linux、Mac OS、Windows 主流操作系统。最大的问题在于维护并不是特别活跃，不过不影响日常使用。</p><h2 id="docker-dashboard" tabindex="-1">Docker Dashboard <a class="header-anchor" href="#docker-dashboard" aria-label="Permalink to &quot;Docker Dashboard&quot;">​</a></h2><p>这是 Docker 官方的 Docker Desktop 提供的功能，亲儿子级别，功能比较单一，只提供了容器镜像的简单管理，容器的简单监控统计。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.12.30/202212100953045.png" alt="image-20221210095304887" style="zoom:80%;"><p>优点就是官方提供，缺点就是功能比较简单，只能管理本地的容器和镜像，另外目前只支持 Mac OS 和 Windows。也就是说只符合日常开发用用。</p><h2 id="重量级" tabindex="-1">重量级 <a class="header-anchor" href="#重量级" aria-label="Permalink to &quot;重量级&quot;">​</a></h2><p>通过docker stats命令可以很方便的看到当前宿主机上所有容器的CPU,内存以及网络流量等数据，一般小公司够用了。但是，<strong>docker stats统计结果只能是当前宿主机的全部容器，数据资料是实时的，没有地方存储、没有健康指标过线预警等功能</strong>。</p><h3 id="容器监控三剑客" tabindex="-1">容器监控三剑客 <a class="header-anchor" href="#容器监控三剑客" aria-label="Permalink to &quot;容器监控三剑客&quot;">​</a></h3><p>简述：CAdvisor监控收集+InfluxDB存储数据+Granfana展示图表</p><h4 id="cadvisor" tabindex="-1">CAdvisor <a class="header-anchor" href="#cadvisor" aria-label="Permalink to &quot;CAdvisor&quot;">​</a></h4><p>它是一个容器资源监控工具，包括容器的内存、CPU、网络IO、磁盘IO等监控，同时提供了一个WEB页面用来查看容器的实时运行状态。它的默认存储2分钟的数据，而且只是针对单物理机。不过它提供了很多数据集成接口，支持InfluxDB、Redis、Kafka、Elasticsearch等集成，可以加上对应配置将监控数据发往这些数据库存储起来。</p><p>主要功能有两点</p><ul><li>展示host和容器两个层次的容器数据</li><li>展示历史变化数据</li></ul><h4 id="influxdb" tabindex="-1">InfluxDB <a class="header-anchor" href="#influxdb" aria-label="Permalink to &quot;InfluxDB&quot;">​</a></h4><p>InfluxDB是用Go语言编写的一个开源分布式时序、事件和指标数据库、无需外部依赖。CAdvisor默认只在本机保存最近两分钟的数据，为了持久化存储数据和统一收集展示监控数据，需要将数据存储到InfluxDB中。</p><p>InfluxDB是一个时序数据库，专门用于存储时序相关数据，很适合存储CAdvisor的数据。而且，CAdvisor本身已经提供了InfluxDB的集成方法，启动容器时指定配置即可。</p><p>主要功能有三点</p><ul><li>基于时间序列，支持与时间有关的相关函数(如最大、最小、求和等)</li><li>可度量性，可以实时对大量数据进行计算</li><li>基于事件：它支持任意的事件数据</li></ul><h4 id="granfana" tabindex="-1">Granfana <a class="header-anchor" href="#granfana" aria-label="Permalink to &quot;Granfana&quot;">​</a></h4><p>它是一个开源数据监控分析可视化平台，支持多种数据源配置(支持的数据源包括InfluxDB、MySQL、ES、OpenTSDB、Graphite等)和丰富的插件及模板功能，支持图表权限控制和报警</p><p>主要特性</p><ul><li>灵魂丰富的图形化选项</li><li>可以支持多种风格</li><li>支持白天和夜间模式</li><li>多个数据源</li></ul><h3 id="使用" tabindex="-1">使用 <a class="header-anchor" href="#使用" aria-label="Permalink to &quot;使用&quot;">​</a></h3><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mkdir </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">p </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydocker</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">cig</span></span>
<span class="line"><span style="color:#A6ACCD;">cd  </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mydocker</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">cig</span></span>
<span class="line"><span style="color:#A6ACCD;">vim docker</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">compose</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">yml</span></span></code></pre></div><div class="language-yml"><button title="Copy Code" class="copy"></button><span class="lang">yml</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F07178;">version</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">3.1</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#F07178;">volumes</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">grafana_data</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">{}</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#F07178;">services</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span><span style="color:#F07178;">influxdb</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">image</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">tutum/influxdb:0.9</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">restart</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">always</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">environment</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">PRE_CREATE_DB=cadvisor</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">ports</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">8083:8083</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">8086:8086</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">volumes</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">./data/influxdb:/data</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;"> </span><span style="color:#F07178;">cadvisor</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">image</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">google/cadvisor</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">links</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">influxdb:influxsrv</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">command</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-storage_driver=influxdb -storage_driver_db=cadvisor -storage_driver_host=influxsrv:8086</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">restart</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">always</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">ports</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">8080:8080</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">volumes</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/:/rootfs:ro</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/var/run:/var/run:rw</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/sys:/sys:ro</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/var/lib/docker/:/var/lib/docker:ro</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;"> </span><span style="color:#F07178;">grafana</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">user</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">104</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">image</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">grafana/grafana</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">user</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">104</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">restart</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">always</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">links</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">influxdb:influxsrv</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">ports</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">3000:3000</span><span style="color:#89DDFF;">&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">volumes</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">grafana_data:/var/lib/grafana</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">environment</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">HTTP_USER=admin</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">HTTP_PASS=admin</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">INFLUXDB_HOST=influxsrv</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">INFLUXDB_PORT=8086</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">INFLUXDB_NAME=cadvisor</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">INFLUXDB_USER=root</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">INFLUXDB_PASS=root</span></span></code></pre></div><p>启动：docker-compose up</p><p>三个服务全都启动完毕</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220213154518119.png" alt="image-20220213154518119" style="zoom:80%;"><p>1、浏览cAdvisor收集服务，<a href="http://192.168.220.130:8080/" target="_blank" rel="noreferrer">http://192.168.220.130:8080/</a></p><p>​ 第一次访问慢，请稍等</p><p>​ cadvisor也有基础的图形展现功能，这里主要用它来作数据采集</p><p>2、浏览influxdb存储服务，<a href="http://192.168.220.130:8083/" target="_blank" rel="noreferrer">http://192.168.220.130:8083/</a></p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220213122026938.png" alt="image-20220213122026938" style="zoom:80%;"><p>3、浏览grafana展现服务，<a href="http://192.168.220.130:3000" target="_blank" rel="noreferrer">http://192.168.220.130:3000</a></p><p>​ ip+3000端口的方式访问,默认帐户密码（admin/admin）</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220213123544095.png" alt="image-20220213123544095" style="zoom:67%;"><p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220213124451763.png" alt="image-20220213124451763"></p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img/image-20220213123748784.png" alt="image-20220213123748784" style="zoom:67%;"><h4 id="配置面板panel" tabindex="-1">配置面板panel <a class="header-anchor" href="#配置面板panel" aria-label="Permalink to &quot;配置面板panel&quot;">​</a></h4><p>&lt; 重点部分</p><p>到这里cAdvisor+InfluxDB+Grafana容器监控系统就部署完成了</p><h1 id="docker-desktop" tabindex="-1">Docker Desktop <a class="header-anchor" href="#docker-desktop" aria-label="Permalink to &quot;Docker Desktop&quot;">​</a></h1><blockquote><p>接下来开始本地实践了，用 Docker 快速搭一套本地环境。有一些 Docker 的可视化客户端可以安装，帮我们更方便更直观的管理镜像、容器，当然如果你很厉害的话，完全用命令行也不是不行。</p></blockquote><h2 id="下载安装" tabindex="-1">下载安装 <a class="header-anchor" href="#下载安装" aria-label="Permalink to &quot;下载安装&quot;">​</a></h2><blockquote><p>访问 Docker Desktop 官网 <a href="https://www.docker.com/products/docker-desktop/%EF%BC%8C%E4%B8%8B%E8%BD%BD%E5%AF%B9%E5%BA%94%E7%9A%84%E7%89%88%E6%9C%AC%E3%80%82" target="_blank" rel="noreferrer">https://www.docker.com/products/docker-desktop/，下载对应的版本。</a></p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.11.17/image-20230726210412585.png" alt="image-20230726210412585" style="zoom:80%;"><blockquote><p>下载完一键安装就可以了，Docker 环境直接帮你装好了，省心省事儿。下面是它的控制台界面。左侧导航可以查看镜像列表、容器列表、映射的Volumes。</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.11.17/image-20230726210432856.png" alt="image-20230726210432856" style="zoom:80%;"><blockquote><p>我们在命令行输入 <code>docker -v</code>，如果出现正确的版本号，说明 docker 服务已经安装正常了。</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.11.17/image-20230726210504985.png" alt="image-20230726210504985" style="zoom:80%;"><blockquote><p>接下来有一件事儿是必须要做的，那就是设置国内镜像源，道理大家都懂，你要是用国外的镜像源，一天都不一定能搞下来一个。</p></blockquote><h2 id="基本设置" tabindex="-1">基本设置 <a class="header-anchor" href="#基本设置" aria-label="Permalink to &quot;基本设置&quot;">​</a></h2><blockquote><p>点击「设置」按钮，在左侧选择「Docker Engine」</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.11.17/image-20230726210929790.png" alt="image-20230726210929790" style="zoom:80%;"><blockquote><p>然后在右侧的配置框中添加如下配置，加到最下面即可：</p></blockquote><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">&quot;registry-mirrors&quot;: [</span></span>
<span class="line"><span style="color:#A6ACCD;">    &quot;https://hi7nmgjd.mirror.aliyuncs.com&quot;</span></span>
<span class="line"><span style="color:#A6ACCD;">]</span></span></code></pre></div><blockquote><p>加完后，点击「Apply &amp; restart」，这时候会重启 Docker 服务。</p></blockquote><h2 id="应用安装" tabindex="-1">应用安装 <a class="header-anchor" href="#应用安装" aria-label="Permalink to &quot;应用安装&quot;">​</a></h2><blockquote><p>MySQL、Nginx、Redis、Zookeeper 这些都是服务，每一个都可以按照这种方式安装，不管你的项目需要多少个服务，一个个安装就好了，很快的呦。</p></blockquote><blockquote><p>正好我最进要学一下 PostgreSQL，我就直接启动一个 docker 容器了，不在本地安装了。当然了，像数据库这种 I/O 型的应用是不建议容器化的，但是本地开发测试无所谓。</p></blockquote><blockquote><p>在这个搜索框输入关键词，查找对应的镜像，我在这里输入关键词 <code>PostgreSQL</code>。如果安装 Nginx 那就是输入 Nginx，以此类推。</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.11.17/image-20230726211003534.png" alt="image-20230726211003534" style="zoom:80%;"><blockquote><p>search看，出来了一大堆，我一般都是找第一个，也就是下载量最大的这个。</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.11.17/image-20230726211013821.png" alt="image-20230726211013821" style="zoom:80%;"><blockquote><p>可以 <code>pull</code> 或者 <code>run</code>，pull 是拉取镜像，run 是拉取镜像+启动容器。</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.11.17/image-20230726211024845.png" alt="image-20230726211024845" style="zoom:67%;"><blockquote><p>一般都是直接 <code>run</code>，点一下 <code>run</code>，等一会儿，因为前面已经设置了国内镜像源，所以速度很快，十几秒钟。（根据网速快慢不同，因为要下载镜像文件，有的应用有上百M）下载完之后，因为选的是 <code>run</code>，所以直接弹出了启动参数。</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.11.17/image-20230726211038970.png" alt="image-20230726211038970" style="zoom:80%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.11.17/image-20230726210647544.png" alt="image-20230726210647544" style="zoom:80%;"><h3 id="设置镜像名称" tabindex="-1"><strong>设置镜像名称</strong> <a class="header-anchor" href="#设置镜像名称" aria-label="Permalink to &quot;**设置镜像名称**&quot;">​</a></h3><blockquote><p>容器名称（Container name）就是为了我们一看到它就知道是干什么的，用来方便管理的，我就直接命名为 <code>PostgreSQL</code>了。</p></blockquote><h3 id="设置端口映射-ports" tabindex="-1"><strong>设置端口映射（Ports）</strong> <a class="header-anchor" href="#设置端口映射-ports" aria-label="Permalink to &quot;**设置端口映射（Ports）**&quot;">​</a></h3><blockquote><p>服务本身有自己的端口，例如 MySQL 是3306，这是服务本身在容器内的启动端口，但最终我们要通过宿主机去访问服务，所以要将这个容器内的端口绑定到一个宿主机端口，这叫做端口映射，这样一来，我们就可以通过宿主机的端口访问到容器内的端口了。比如将 MySQL 容器的 <code>3306</code> 端口映射到宿主机的 <code>13306</code> 端口，之后在设置数据库连接的时候，就用本机 IP:13306就能访问 MySQL 容器了。</p></blockquote><blockquote><p>在这个 PostgreSQL 容器上，将本机的 <code>15432</code>和容器的 <code>5432</code>端口绑定，之后就可以用 <code>15432</code>做连接端口了。</p></blockquote><h3 id="目录映射-volumes" tabindex="-1"><strong>目录映射（Volumes）</strong> <a class="header-anchor" href="#目录映射-volumes" aria-label="Permalink to &quot;**目录映射（Volumes）**&quot;">​</a></h3><blockquote><p>很多服务都会用到存储目录，但是容器本身就在宿主机上，所以需要将服务在容器内的目录映射到宿主机的目录上，这叫目录映射。例如将 Nginx 容器的 <code>/etc/nginx</code>目录映射到宿主机的 <code>/apps/nginx/</code>目录上，那之后在宿主机访问 <code>/apps/nginx</code>目录时，就能看到 Nginx 容器的配置文件了。</p></blockquote><blockquote><p>在这个PostgreSQL 容器上，作者将 <code>/etc/postgresql/postgresql.conf</code>配置文件映射到了其本地的一个目录上。</p></blockquote><h3 id="环境变量" tabindex="-1">环境变量 <a class="header-anchor" href="#环境变量" aria-label="Permalink to &quot;环境变量&quot;">​</a></h3><blockquote><p>一个服务启动可能会用到启动变量，这些变量可以通过环境变量的方式进行配置。例如，我们启动一个 Java jar 包，要配置 JVM 相关的参数，这些参数就可以放到环境变量中，供启动的时候使用。</p></blockquote><blockquote><p>因为 PostgreSQL 需要密码，所以这里就设置一个密码的环境变量 <code>POSTGRES_PASSWORD</code>。都设置好之后，点击<code>run</code>按钮，启动容器。然后我们看到容器已经启动了，有相应的日志打印出来。</p></blockquote><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.11.17/image-20230726211112465.png" alt="image-20230726211112465" style="zoom:80%;"><p>然后点击左侧的<code>Containers</code>，可以看到已经启动的容器和一些基本配置。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.11.17/image-20230726211121880.png" alt="image-20230726211121880" style="zoom:80%;"><p>然后就可以通过客户端进行连接了。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.11.17/image-20230726211132058.png" alt="image-20230726211132058" style="zoom:80%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.11.17/image-20230726211141617.png" alt="image-20230726211141617" style="zoom:80%;"><p>另外，还可以在容器详情中查看容器的内部文件、状态、配置信息、日志等，以及进入命令行。</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2023.11.17/image-20230726211156424.png" alt="image-20230726211156424" style="zoom:80%;"><h1 id="docker不适合部署数据库原因" tabindex="-1">Docker不适合部署数据库原因 <a class="header-anchor" href="#docker不适合部署数据库原因" aria-label="Permalink to &quot;Docker不适合部署数据库原因&quot;">​</a></h1><h2 id="_1、数据安全问题" tabindex="-1">1、数据安全问题 <a class="header-anchor" href="#_1、数据安全问题" aria-label="Permalink to &quot;1、数据安全问题&quot;">​</a></h2><blockquote><p>不要将数据储存在容器中，这也是 Docker 官方容器使用技巧中的一条。容器随时可以停止、或者删除。当容器被rm掉，容器里的数据将会丢失。为了避免数据丢失，用户可以使用数据卷挂载来存储数据。但是容器的 Volumes 设计是围绕 Union FS 镜像层提供持久存储，数据安全缺乏保证。</p></blockquote><blockquote><p>如果容器突然崩溃，数据库未正常关闭，可能会损坏数据。另外，容器里共享数据卷组，对物理机硬件损伤也比较大。即使你要把 Docker 数据放在主机来存储 ，它依然不能保证不丢数据。Docker volumes 的设计围绕 Union FS 镜像层提供持久存储，但它仍然缺乏保证。</p></blockquote><blockquote><p>使用当前的存储驱动程序，Docker 仍然存在不可靠的风险。如果容器崩溃并数据库未正确关闭，则可能会损坏数据。</p></blockquote><h2 id="_2、性能问题" tabindex="-1">2、性能问题 <a class="header-anchor" href="#_2、性能问题" aria-label="Permalink to &quot;2、性能问题&quot;">​</a></h2><blockquote><p>大家都知道，MySQL 属于关系型数据库，对IO要求较高。当一台物理机跑多个时，IO就会累加，导致IO瓶颈，大大降低 MySQL 的读写性能。</p></blockquote><blockquote><p>在一次Docker应用的十大难点专场上，某国有银行的一位架构师也曾提出过：“数据库的性能瓶颈一般出现在IO上面，如果按 Docker 的思路，那么多个docker最终IO请求又会出现在存储上面。现在互联网的数据库多是share nothing的架构，可能这也是不考虑迁移到 Docker 的一个因素吧”。</p></blockquote><p><strong>针对性能问题有些同学可能也有相对应的方案来解决：</strong></p><p>数据库程序与数据分离</p><blockquote><p>如果使用Docker 跑 MySQL，数据库程序与数据需要进行分离，将数据存放到共享存储，程序放到容器里。如果容器有异常或 MySQL 服务异常，自动启动一个全新的容器。另外，建议不要把数据存放到宿主机里，宿主机和容器共享卷组，对宿主机损坏的影响比较大。</p></blockquote><p>跑轻量级或分布式数据库</p><blockquote><p>Docker 里部署轻量级或分布式数据库，Docker 本身就推荐服务挂掉，自动启动新容器，而不是继续重启容器服务。</p></blockquote><p>合理布局应用</p><blockquote><p>对于IO要求比较高的应用或者服务，将数据库部署在物理机或者KVM中比较合适。目前TX云的TDSQL和阿里的Oceanbase都是直接部署在物理机器，而非Docker 。</p></blockquote><h2 id="_3、网络问题" tabindex="-1">3、网络问题 <a class="header-anchor" href="#_3、网络问题" aria-label="Permalink to &quot;3、网络问题&quot;">​</a></h2><blockquote><p>要理解 Docker 网络，您必须对网络虚拟化有深入的了解。也必须准备应付好意外情况。你可能需要在没有支持或没有额外工具的情况下，进行 bug 修复。</p></blockquote><blockquote><p>我们知道：数据库需要专用的和持久的吞吐量，以实现更高的负载。我们还知道容器是虚拟机管理程序和主机虚拟机背后的一个隔离层。然而网络对于数据库复制是至关重要的，其中需要主从数据库间 24/7 的稳定连接。未解决的 Docker 网络问题在1.9版本依然没有得到解决。</p></blockquote><blockquote><p>把这些问题放在一起，容器化使数据库容器很难管理。我知道你是一个顶级的工程师，什么问题都可以得到解决。但是，你需要花多少时间解决 Docker 网络问题？将数据库放在专用环境不会更好吗？节省时间来专注于真正重要的业务目标。</p></blockquote><h2 id="_4、状态" tabindex="-1">4、状态 <a class="header-anchor" href="#_4、状态" aria-label="Permalink to &quot;4、状态&quot;">​</a></h2><blockquote><p>在 Docker 中打包无状态服务是很酷的，可以实现编排容器并解决单点故障问题。但是数据库呢？将数据库放在同一个环境中，它将会是有状态的，并使系统故障的范围更大。下次您的应用程序实例或应用程序崩溃，可能会影响数据库。</p></blockquote><p><strong>知识点</strong>在 Docker 中水平伸缩只能用于无状态计算服务，而不是数据库。</p><blockquote><p>Docker 快速扩展的一个重要特征就是无状态，具有数据状态的都不适合直接放在 Docker 里面，如果 Docker 中安装数据库，存储服务需要单独提供。</p></blockquote><blockquote><p>目前，TX云的TDSQL(金融分布式数据库)和阿里云的Oceanbase(分布式数据库系统)都直接运行中在物理机器上，并非使用便于管理的 Docker 上。</p></blockquote><h2 id="_5、资源隔离" tabindex="-1">5、资源隔离 <a class="header-anchor" href="#_5、资源隔离" aria-label="Permalink to &quot;5、资源隔离&quot;">​</a></h2><blockquote><p>资源隔离方面，Docker 确实不如虚拟机KVM，Docker是利用Cgroup实现资源限制的，只能限制资源消耗的最大值，而不能隔绝其他程序占用自己的资源。如果其他应用过渡占用物理机资源，将会影响容器里 MySQL 的读写效率。</p></blockquote><blockquote><p>需要的隔离级别越多，获得的资源开销就越多。相比专用环境而言，容易水平伸缩是Docker的一大优势。然而在 Docker 中水平伸缩只能用于无状态计算服务，数据库并不适用。</p></blockquote><blockquote><p>我们没有看到任何针对数据库的隔离功能，那为什么我们应该把它放在容器中呢？</p></blockquote><h2 id="_6、云平台的不适用性" tabindex="-1">6、云平台的不适用性 <a class="header-anchor" href="#_6、云平台的不适用性" aria-label="Permalink to &quot;6、云平台的不适用性&quot;">​</a></h2><blockquote><p>大部分人通过共有云开始项目。云简化了虚拟机操作和替换的复杂性，因此不需要在夜间或周末没有人工作时间来测试新的硬件环境。当我们可以迅速启动一个实例的时候，为什么我们需要担心这个实例运行的环境？</p></blockquote><blockquote><p>这就是为什么我们向云提供商支付很多费用的原因。当我们为实例放置数据库容器时，上面说的这些便利性就不存在了。因为数据不匹配，新实例不会与现有的实例兼容，如果要限制实例使用单机服务，应该让 DB 使用非容器化环境，我们仅仅需要为计算服务层保留弹性扩展的能力。</p></blockquote><h2 id="_7、运行数据库的环境需求" tabindex="-1">7、运行数据库的环境需求 <a class="header-anchor" href="#_7、运行数据库的环境需求" aria-label="Permalink to &quot;7、运行数据库的环境需求&quot;">​</a></h2><blockquote><p>常看到 DBMS 容器和其他服务运行在同一主机上。然而这些服务对硬件要求是非常不同的。</p></blockquote><blockquote><p>数据库（特别是关系型数据库）对 IO 的要求较高。一般数据库引擎为了避免并发资源竞争而使用专用环境。如果将你的数据库放在容器中，那么将浪费你的项目的资源。因为你需要为该实例配置大量额外的资源。在公有云，当你需要 34G 内存时，你启动的实例却必须开 64G 内存。在实践中，这些资源并未完全使用。</p></blockquote><blockquote><p>怎么解决？您可以分层设计，并使用固定资源来启动不同层次的多个实例。水平伸缩总是比垂直伸缩更好。针对上面问题是不是说数据库一定不要部署在容器里吗？</p></blockquote><p>答案是：并不是</p><blockquote><p>我们可以把数据丢失不敏感的业务（搜索、埋点）就可以数据化，利用数据库分片来来增加实例数，从而增加吞吐量。docker适合跑轻量级或分布式数据库，当docker服务挂掉，会自动启动新容器，而不是继续重启容器服务。数据库利用中间件和容器化系统能够自动伸缩、容灾、切换、自带多个节点，也是可以进行容器化的。</p></blockquote><h1 id="idea使用docker" tabindex="-1">IDEA使用Docker <a class="header-anchor" href="#idea使用docker" aria-label="Permalink to &quot;IDEA使用Docker&quot;">​</a></h1><h2 id="连接配置" tabindex="-1">连接配置 <a class="header-anchor" href="#连接配置" aria-label="Permalink to &quot;连接配置&quot;">​</a></h2><p>由于该插件为IDEA内置插件，直接在插件设置中启用就好了；</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.30/202207231113690.png" alt="image-20220723111359625" style="zoom:67%;"><h3 id="修改端口号" tabindex="-1">修改端口号 <a class="header-anchor" href="#修改端口号" aria-label="Permalink to &quot;修改端口号&quot;">​</a></h3><p>1、修改/lib/systemd/system/docker.service文件</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">vim </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">lib</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">systemd</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">system</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">docker</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">service</span></span></code></pre></div><p>按i进入编辑模式，在ExecStart后面追加，默认端口是2375，也可以修改为其他端口</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">H tcp:</span><span style="color:#89DDFF;">//</span><span style="color:#F78C6C;">0.0.0.0</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">2375</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">H unix:</span><span style="color:#89DDFF;">//</span><span style="color:#A6ACCD;">var</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">run</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">docker</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">sock</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.30/202207231124926.png" alt="image-20220723112400760" style="zoom:67%;"><p>修改完记得写保存退出命令 :wq</p><p>2、重新加载配置文件，重启docker，使得刚才的配置生效</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;">重新加载配置文件</span></span>
<span class="line"><span style="color:#A6ACCD;">systemctl daemon</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">reload</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;">重启docker服务</span></span>
<span class="line"><span style="color:#A6ACCD;">systemctl restart docker</span></span></code></pre></div><p>3、使用curl命令检查是否开启</p><p>curl下载docker的服务信息</p><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">curl http:</span><span style="color:#89DDFF;">//</span><span style="color:#F78C6C;">127.0.0.1</span><span style="color:#A6ACCD;">:</span><span style="color:#F78C6C;">2375</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">info</span></span></code></pre></div><p>如果有返回说明，就证明开启成功了，可以看到我的Docker版本，镜像加速器地址等其他信息</p><h2 id="连接" tabindex="-1">连接 <a class="header-anchor" href="#连接" aria-label="Permalink to &quot;连接&quot;">​</a></h2><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.30/202207231128218.png" alt="image-20220723112807101" style="zoom:80%;"><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.30/202207231133863.png" alt="image-20220723113302764" style="zoom:67%;"><h2 id="镜像管理" tabindex="-1">镜像管理 <a class="header-anchor" href="#镜像管理" aria-label="Permalink to &quot;镜像管理&quot;">​</a></h2><p>点击<code>Images</code>按钮，输入需要下载的镜像名称和版本号就可以下载镜像了，这里IDEA还支持自动提示，实在太贴心了！</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.30/202207231138952.png" alt="image-20220723113829851" style="zoom:67%;"><p>右键指定镜像打开菜单，我们还可以对其进行创建容器、查看、删除等常规操作；</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.30/202207231138612.png" alt="image-20220723113855528" style="zoom:67%;"><h2 id="springboot" tabindex="-1">SpringBoot <a class="header-anchor" href="#springboot" aria-label="Permalink to &quot;SpringBoot&quot;">​</a></h2><p>当然我们还可以使用Dockerfile来构建自己的镜像，这里以我的<a href="https://mp.weixin.qq.com/s?__biz=MzU1Nzg4NjgyMw==&amp;mid=2247500084&amp;idx=1&amp;sn=5bd4e684af3cfede8f332c423a478abf&amp;scene=21#wechat_redirect" target="_blank" rel="noreferrer">mall-tiny</a> 脚手架项目为例，首先准备好Dockerfile脚本；</p><p>SpingBoot项目打包</p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.30/202207231143627.png" alt="image-20220723114343561" style="zoom:50%;"><div class="language-apl"><button title="Copy Code" class="copy"></button><span class="lang">apl</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 该镜像需要依赖的基础镜像</span></span>
<span class="line"><span style="color:#A6ACCD;">FROM java:</span><span style="color:#F78C6C;">8</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 将当前目录下的jar包复制到docker容器的</span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">目录下</span></span>
<span class="line"><span style="color:#A6ACCD;">ADD </span><span style="color:#89DDFF;">./</span><span style="color:#A6ACCD;">mall</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">tiny</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">1.0.0</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">SNAPSHOT</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">jar </span><span style="color:#89DDFF;">/</span><span style="color:#A6ACCD;">mall</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">tiny</span><span style="color:#89DDFF;">-</span><span style="color:#F78C6C;">1.0.0</span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;">SNAPSHOT</span><span style="color:#89DDFF;">.</span><span style="color:#A6ACCD;">jar</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 声明服务运行在</span><span style="color:#F78C6C;">8080</span><span style="color:#A6ACCD;">端口</span></span>
<span class="line"><span style="color:#A6ACCD;">EXPOSE </span><span style="color:#F78C6C;">8080</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 指定docker容器启动时运行jar包</span></span>
<span class="line"><span style="color:#A6ACCD;">ENTRYPOINT </span><span style="color:#89DDFF;">[</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">java</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">-jar</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">,</span><span style="color:#89DDFF;">&quot;</span><span style="color:#C3E88D;">/mall-tiny-1.0.0-SNAPSHOT.jar</span><span style="color:#89DDFF;">&quot;</span><span style="color:#89DDFF;">]</span></span>
<span class="line"><span style="color:#89DDFF;">#</span><span style="color:#A6ACCD;"> 指定维护者的名字</span></span>
<span class="line"><span style="color:#A6ACCD;">MAINTAINER renshuo</span></span></code></pre></div><ul><li>然后打开Dockfile文件，点击左侧按钮选择创建新的运行配置；</li></ul><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.30/202207231149548.png" alt="image-20220723114914461" style="zoom:67%;"><ul><li>接下来选择我们配置好的远程Docker服务，配置好应用打包目录及镜像名称；</li></ul><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.6.30/202207231149031.png" alt="image-20220723114928921" style="zoom:50%;"><ul><li>然后选择打包镜像，控制台将输出如下日志，jar包会直接上传到远程服务器并打包成镜像。</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwlgbAHTzCeianViblv68lEa8d4OxMqC7W8kwibciayicCn4hsXvC7TibWtZawYq7xFUBkhQRz6eEyjse0Sw/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><h2 id="容器管理" tabindex="-1">容器管理 <a class="header-anchor" href="#容器管理" aria-label="Permalink to &quot;容器管理&quot;">​</a></h2><ul><li>右键镜像打开菜单，还可以直接创建容器；</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwlgbAHTzCeianViblv68lEa8dsH4a0hy45rxPiaPv6ddft9cWt4Eo5UN33kw2781yqyv8Za6lcoxZXEg/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><ul><li>由于mall-tiny项目需要用到mysql和redis服务，我们可以先启动它们；</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwlgbAHTzCeianViblv68lEa8deb04hTmdYEjKAprBiadmJCLoiafSl1xILbicTnH0vB0pxNu5FibmSmib3mQ/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><ul><li>然后修改创建容器的配置，主要就是一些之前使用<code>docker run</code>命令的指定的一些配置；</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwlgbAHTzCeianViblv68lEa8dcKsHEEUY9LjXeL6Yy7zmzYeGEuuzvx6MTdmF13aYFNicFqibScx7IeTQ/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><ul><li>大家直接对照下之前使用的<code>docker run</code>命令，大概就能知道这些配置的作用了；</li></ul><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run -p 8080:8080 --name mall-tiny \</span></span>
<span class="line"><span style="color:#A6ACCD;">--link mysql:db \</span></span>
<span class="line"><span style="color:#A6ACCD;">--link redis:redis \</span></span>
<span class="line"><span style="color:#A6ACCD;">-e &#39;spring.profiles.active&#39;=prod \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v /etc/localtime:/etc/localtime \</span></span>
<span class="line"><span style="color:#A6ACCD;">-v /mydata/app/mall-tiny/logs:/var/logs \</span></span>
<span class="line"><span style="color:#A6ACCD;">-d mall-tiny/mall-tiny:1.0.0-SNAPSHOT</span></span></code></pre></div><ul><li>运行过程中可以直接在<code>Log</code>标签中查看容器的运行日志，这确实很方便！</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwlgbAHTzCeianViblv68lEa8djCDhs0uUibSMzTUyWF5g28KFntkWbRkyySYjcpsUpRiakKJVQQlo86DA/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><h2 id="与容器交互" tabindex="-1">与容器交互 <a class="header-anchor" href="#与容器交互" aria-label="Permalink to &quot;与容器交互&quot;">​</a></h2><ul><li>通过容器面板我们可以查看到很多容器内部信息，比如查看环境变量；</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwlgbAHTzCeianViblv68lEa8d9LkSl8WLY1MM1N7LibplH6JJ6UHGTz71v5ZKwB2TCDh0CpcYsoN97rQ/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><ul><li>还可以查看容器的端口映射配置；</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwlgbAHTzCeianViblv68lEa8dr7ibzqv5LCtxnjyOrR91IZLNnMhEp3Xx37RVOh9bZduWiaCtETZJeibBw/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><ul><li>还可以查看之前通过<code>docker inspect</code>命令获取的信息，比如查看容器运行的IP地址；</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwlgbAHTzCeianViblv68lEa8dJpaBJibVuY1ciaBuiaW6CUSJYjcp3bsCMH3dVfXKJsbUNAia9Ma83OD62Q/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><ul><li>还可以直接进入容器内部去执行命令，还记得之前使用的<code>docker exec -it</code>命令么。</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwlgbAHTzCeianViblv68lEa8dwE3WBwyMS4SE0hb06AletgX6iafuVm7QgUxPFhC1lFuHwezjONAwGEQ/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><h2 id="docker-compose" tabindex="-1">Docker Compose <a class="header-anchor" href="#docker-compose" aria-label="Permalink to &quot;Docker Compose&quot;">​</a></h2><ul><li>使用该插件也可以通过Docker Compose来部署应用，首先创建<code>docker-compose.yml</code>文件，由于mysql容器没有使用Docker Compose来创建，这里改用IP来访问；</li></ul><div class="language-yml"><button title="Copy Code" class="copy"></button><span class="lang">yml</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#F07178;">version</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">3</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#F07178;">services</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">redis</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">image</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">redis:5</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">container_name</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">redis-tiny</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">command</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">redis-server --appendonly yes</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">volumes</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/mydata/redis-tiny/data:/data</span><span style="color:#A6ACCD;"> </span><span style="color:#676E95;font-style:italic;">#数据文件挂载</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">ports</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">6379:6379</span></span>
<span class="line"><span style="color:#A6ACCD;">  </span><span style="color:#F07178;">mall-tiny</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">image</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mall-tiny/mall-tiny:1.0.0-SNAPSHOT</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">container_name</span><span style="color:#89DDFF;">:</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mall-tiny</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">links</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">redis:redis</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">depends_on</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">redis</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">ports</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">8080:8080</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">environment</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">spring.profiles.active=prod</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">spring.datasource.url=jdbc:mysql://192.168.3.105:3306/mall_tiny? useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=Asia/Shanghai&amp;useSSL=false</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">&#39;</span><span style="color:#C3E88D;">spring.redis.host=redis</span><span style="color:#89DDFF;">&#39;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">volumes</span><span style="color:#89DDFF;">:</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/etc/localtime:/etc/localtime</span></span>
<span class="line"><span style="color:#A6ACCD;">      </span><span style="color:#89DDFF;">-</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/mydata/app/mall-tiny/logs:/var/logs</span></span></code></pre></div><ul><li>然后直接点击<code>docker-compose.yml</code>文件箭头即可将应用部署到远程服务器，确实很方便！</li></ul><p><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwlgbAHTzCeianViblv68lEa8d3c1NWicpdBxPdXbcU8g1trdtYwIxibgpm1GrrLEmY8fwGTUmAbUjsseQ/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><ul><li>部署完成后即可访问项目的Swagger页面，访问地址：<a href="http://192.168.3.105:8080/swagger-ui/" target="_blank" rel="noreferrer">http://192.168.3.105:8080/swagger-ui/</a></li></ul><img src="https://mmbiz.qpic.cn/mmbiz_png/CKvMdchsUwlgbAHTzCeianViblv68lEa8dbOE2RxSznRq47s4xa5ibMXWx0NyibDUDWdvcicZVeB8O4b2wApQMCtib6A/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片" style="zoom:50%;"><blockquote><p>今天体验了一把IDEA的官方Docker插件，不使用命令行就可以实现远程Docker镜像与容器的管理，还支持Docker Compose部署，功能确实很强大！在平时开发过程中，使用这款插件来打包、部署、运行SpringBoot应用确实很方便，感兴趣的小伙伴可以尝试下它！</p></blockquote><h1 id="docker-部署前后端分离项目" tabindex="-1">Docker 部署前后端分离项目 <a class="header-anchor" href="#docker-部署前后端分离项目" aria-label="Permalink to &quot;Docker 部署前后端分离项目&quot;">​</a></h1><p><a href="https://mp.weixin.qq.com/s?__biz=MzAwMjI0ODk0NA==&amp;mid=2451968557&amp;idx=1&amp;sn=4a40968c69a17df511cd7865eebe5320&amp;chksm=8d1febb2ba6862a47676d1e492666d2edc503a0ef3c10360125256619bb1457d9ad967b4b746&amp;mpshare=1&amp;scene=23&amp;srcid=0302HIxi6ycu2a3VHKWtMCgM&amp;sharer_sharetime=1677767187330&amp;sharer_shareid=29b8a04db1dbd975e3bf4e9f47e7ac67#rd" target="_blank" rel="noreferrer">丝滑的打包部署，一套带走，还没搞</a></p><h2 id="安装nginx" tabindex="-1">安装Nginx <a class="header-anchor" href="#安装nginx" aria-label="Permalink to &quot;安装Nginx&quot;">​</a></h2><h3 id="_1、拉取nginx镜像文件" tabindex="-1">1、拉取Nginx镜像文件 <a class="header-anchor" href="#_1、拉取nginx镜像文件" aria-label="Permalink to &quot;1、拉取Nginx镜像文件&quot;">​</a></h3><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker pull nginx</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.12.30/202212062318039.png" alt="image-20221206231838871" style="zoom:80%;"><h3 id="_2、查看下载好的镜像文件" tabindex="-1">2、查看下载好的镜像文件 <a class="header-anchor" href="#_2、查看下载好的镜像文件" aria-label="Permalink to &quot;2、查看下载好的镜像文件&quot;">​</a></h3><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker images</span></span></code></pre></div><h3 id="_3、创建并运行nginx容器" tabindex="-1">3、创建并运行Nginx容器 <a class="header-anchor" href="#_3、创建并运行nginx容器" aria-label="Permalink to &quot;3、创建并运行Nginx容器&quot;">​</a></h3><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run -d --name nginx01 -p 3344:80 nginx</span></span>
<span class="line"><span style="color:#A6ACCD;">命令详解：</span></span>
<span class="line"><span style="color:#A6ACCD;"># docker run 启动一个镜像</span></span>
<span class="line"><span style="color:#A6ACCD;"># -d 表示后台允许</span></span>
<span class="line"><span style="color:#A6ACCD;"># --name nginx01  表示为当前容器起一个别名</span></span>
<span class="line"><span style="color:#A6ACCD;"># -p 3344:80 表示将本机的3344端口映射到nginx镜像的80端口</span></span></code></pre></div><h3 id="_4、查看正在运行的容器" tabindex="-1">4、查看正在运行的容器 <a class="header-anchor" href="#_4、查看正在运行的容器" aria-label="Permalink to &quot;4、查看正在运行的容器&quot;">​</a></h3><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker ps</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.12.30/202212062319416.png" alt="image-20221206231951171" style="zoom:80%;"><h3 id="_5、查看nginx是否部署成功" tabindex="-1">5、查看Nginx是否部署成功 <a class="header-anchor" href="#_5、查看nginx是否部署成功" aria-label="Permalink to &quot;5、查看Nginx是否部署成功&quot;">​</a></h3><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">curl localhost:3344</span></span></code></pre></div><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.12.30/202212062320207.png" alt="image-20221206232022048" style="zoom:67%;"><p>访问：<a href="http://192.168.22.150:3344/" target="_blank" rel="noreferrer">http://192.168.22.150:3344/</a></p><img src="https://edu-8673.oss-cn-beijing.aliyuncs.com/img2022.12.30/202212062321102.png" alt="image-20221206232102965" style="zoom:67%;"><h3 id="_6、拓展-完整nginx部署" tabindex="-1">6、拓展(完整Nginx部署) <a class="header-anchor" href="#_6、拓展-完整nginx部署" aria-label="Permalink to &quot;6、拓展(完整Nginx部署)&quot;">​</a></h3><p>1、进入Nginx容器当中</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">exec</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-it</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx01</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/bin/bash</span></span>
<span class="line"><span style="color:#FFCB6B;">命令详解：</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># docker exec 在运行的容器中执行命令</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># -i 以交互模式运行容器，通常与 -t 同时使用；例如-it</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># -t 为容器重新分配一个伪输入终端，通常与 -i 同时使用；例如-it</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># nginx01 容器名</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># /bin/bash 其实就是表示载入容器后运行bash（命令语言解释程序）, 因为docker中必须要保持一个进程（运行的程序）的运行，要不然整个容器就会退出，所以说，bash就担任起了docker中运行的那个进程的角色！</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#而/bin/bash则是bash在linux下的位置</span></span></code></pre></div><p>2、在容器中查询出nginx的相关配置文件存放位置</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">whereis nginx</span></span></code></pre></div><p>3、退出容器，回到本地linux系统</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">exit</span></span></code></pre></div><p>4、停止并移除Nginx容器</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker stop bedfd2a72585 #停止容器</span></span>
<span class="line"><span style="color:#A6ACCD;">docker rm bedfd2a72585 #移除容器</span></span>
<span class="line"><span style="color:#A6ACCD;"># bedfd2a72585表示容器的ID，即：CONTAINER ID</span></span></code></pre></div><p>5、本地创建管理目录</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">mkdir -p /data/nginx</span></span>
<span class="line"><span style="color:#A6ACCD;">mkdir -p /data/nginx/www </span></span>
<span class="line"><span style="color:#A6ACCD;">mkdir -p /data/nginx/conf</span></span>
<span class="line"><span style="color:#A6ACCD;">mkdir -p /data/nginx/logs</span></span></code></pre></div><p>6、将容器中的相应文件copy到刚创建的管理目录中</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker cp bedfd2a72585:/etc/nginx/nginx.conf /data/nginx/</span></span>
<span class="line"><span style="color:#A6ACCD;">docker cp bedfd2a72585:/etc/nginx/conf.d /data/nginx/conf/</span></span>
<span class="line"><span style="color:#A6ACCD;">docker cp bedfd2a72585:/usr/share/nginx/html/ /data/nginx/www/</span></span>
<span class="line"><span style="color:#A6ACCD;">docker cp bedfd2a72585:/var/log/nginx/ /data/nginx/logs/</span></span></code></pre></div><blockquote><p>注：docker cp bedfd2a72585中的 &quot;bedfd2a72585&quot; 为容器ID（docker ps可查看）</p></blockquote><p>7、再次启动容器并作目录挂载</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run --name nginx -p 80:80 -v /data/nginx/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/www/:/usr/share/nginx/html/ -v /data/nginx/logs/:/var/log/nginx/ -v /data/nginx/conf/:/etc/nginx/conf.d --privileged=true -d nginx</span></span></code></pre></div><blockquote><p>ps：-p 80:80 端口进行映射，将本地 80端口映射到容器内部的 80 端口。</p></blockquote><h2 id="安装mysql" tabindex="-1">安装MySQL <a class="header-anchor" href="#安装mysql" aria-label="Permalink to &quot;安装MySQL&quot;">​</a></h2><p>1、下拉mysql镜像文件</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">pull</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mysql</span><span style="color:#A6ACCD;">  </span><span style="color:#676E95;font-style:italic;">#默认最新版本</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">pull</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">mysql:xxx</span><span style="color:#A6ACCD;">  </span><span style="color:#676E95;font-style:italic;">#指定版本号</span></span></code></pre></div><p><img src="https://mmbiz.qpic.cn/mmbiz_png/eQPyBffYbuezCBTbVJYp5fkWL9HwqdBe7VyZpv9eezgglxUgmZg5PzOgp9KnSJEicQXXL2dNu3qUCwiamcwVGDDA/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><p>2、查看当前镜像</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker images</span></span></code></pre></div><p><img src="https://mmbiz.qpic.cn/mmbiz_png/eQPyBffYbuezCBTbVJYp5fkWL9HwqdBe892yGsYkibOkEia1aY9Q9MUa4EVKA3wicRbcgricPeZKgkPSyprVyreic5A/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><p>3、启动mysql容器</p><p>第一种：</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run --name mysql01 -d -p 3310:3306 -e MYSQL_ROOT_PASSWORD=root mysql</span></span></code></pre></div><p>命令详解：</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;"># --name 自定义容器名称</span></span>
<span class="line"><span style="color:#A6ACCD;"># -d 后台运行</span></span>
<span class="line"><span style="color:#A6ACCD;"># -p 指定映射的端口号</span></span>
<span class="line"><span style="color:#A6ACCD;"># -e MYSQL_ROOT_PASSWORD=root 数据库密钥</span></span></code></pre></div><p>第二种：</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run --restart=always --privileged=true -d -v /home/mysql/data:/var/lib/mysql -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/my.cnf:/etc/mysql/my.cnf -p 3311:3306 --name mysql02 -e MYSQL_ROOT_PASSWORD=root mysql</span></span></code></pre></div><ul><li><code>--restart=always</code> 代表开启启动</li><li><code>--privileged=true</code> 代表进入容器内部为管理员身份</li><li><code>-d</code> 表示后台运行容器 并返回容器Id</li><li><code>-v</code> 把mysql产生的数据同步到本地 防止数据丢失</li><li><code>-e</code> 容器传参 设置mysql的初始密码</li></ul><p>4、查看正在运行的容器</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker ps</span></span></code></pre></div><p><img src="https://mmbiz.qpic.cn/mmbiz_png/eQPyBffYbuezCBTbVJYp5fkWL9HwqdBeM0NvWMHwZbFkfVd3TxQ43TBX2FiauY21LWYrtbKiaMujct8F5o3GU1sA/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><p>5、测试数据库连接</p><p><img src="https://mmbiz.qpic.cn/mmbiz_png/eQPyBffYbuezCBTbVJYp5fkWL9HwqdBezvTOZEn3PM37k4Xialiak09phLV8aWX0WpyYeVHDreW58KW58fzLKicYA/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><p><img src="https://mmbiz.qpic.cn/mmbiz_png/eQPyBffYbuezCBTbVJYp5fkWL9HwqdBeHysCpJ3FyAT3uIPbptcbhOtuicswo0VlZE5lIicJibzhPsYkwWQaLdK2Q/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><h2 id="部署springboot项目" tabindex="-1">部署SpringBoot项目 <a class="header-anchor" href="#部署springboot项目" aria-label="Permalink to &quot;部署SpringBoot项目&quot;">​</a></h2><p>1、整合后端成Jar包并编写Dockerfile文件</p><p><img src="https://mmbiz.qpic.cn/mmbiz_png/eQPyBffYbuezCBTbVJYp5fkWL9HwqdBexz20m8hBkhb96xayHIf19fy5C6LedkHJZUjia0och2fdmTVvfoaFZrg/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><p>2、Dockerfile内容详解</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">FROM java:8  #工程java版本</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">COPY *.jar /app.jar  #将所有的jar包整合为app.jar</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">EXPOSE 9099  #暴露后端端口号</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">ENTRYPOINT [&quot;java&quot;,&quot;-jar&quot;,&quot;app.jar&quot;]  #执行jar包</span></span></code></pre></div><p>3、将文件上传到Linux服务器上面，必须放在同级目录一起！</p><p><img src="https://mmbiz.qpic.cn/mmbiz_png/eQPyBffYbuezCBTbVJYp5fkWL9HwqdBeNhqnV0DS5IwxofAKAYVHVgMOKyOr6xjqxPFEtBsTnoZa37YVW6vY2g/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><p>4、构建镜像</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker build -t api .  #点千万别漏了，这里取名镜像为api，可以随便取名！</span></span></code></pre></div><p><img src="https://mmbiz.qpic.cn/mmbiz_png/eQPyBffYbuezCBTbVJYp5fkWL9HwqdBeyXYutfLSNpftzPWt0WnDH42kAYDSw1VPNpFlFf0uPSOnTedq0Z3qgw/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><p>5、查看当前镜像</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker images</span></span></code></pre></div><p><img src="https://mmbiz.qpic.cn/mmbiz_png/eQPyBffYbuezCBTbVJYp5fkWL9HwqdBeSBxOqyJNOUic1JDPn4ianvPdT9pL6GAmOG9dcJzeIg8liaibjMBYZWpWYw/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><p>6、创建一个新的容器并运行</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker run -d -p 9099:9099 --name httapi api </span></span>
<span class="line"><span style="color:#A6ACCD;">#将9099端口映射到9099端口，端口记得放开</span></span>
<span class="line"><span style="color:#A6ACCD;">#httapi为自定义容器名字</span></span>
<span class="line"><span style="color:#A6ACCD;">#api是镜像名字</span></span></code></pre></div><p>7、查看正在运行的容器</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker ps</span></span></code></pre></div><p>8、使用postman测试接口</p><p><img src="https://mmbiz.qpic.cn/mmbiz_png/eQPyBffYbuezCBTbVJYp5fkWL9HwqdBevaQWoDZjY8ia8ot7MU5MLIAjnJjvW3eaF3X35njqgTRdr7iabwuGoeew/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><h2 id="部署vue项目" tabindex="-1">部署Vue项目 <a class="header-anchor" href="#部署vue项目" aria-label="Permalink to &quot;部署Vue项目&quot;">​</a></h2><h3 id="_1、打包vue工程" tabindex="-1">1、打包Vue工程 <a class="header-anchor" href="#_1、打包vue工程" aria-label="Permalink to &quot;1、打包Vue工程&quot;">​</a></h3><p><img src="https://mmbiz.qpic.cn/mmbiz_png/eQPyBffYbuezCBTbVJYp5fkWL9HwqdBeSoiaLicZNOqDCBX7s6v1yibwmLwDjIMUWBJwVKKZlEYv9GPMtcyVppZwA/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><h3 id="_2、default-conf文件和dockerfile文件详细" tabindex="-1">2、default.conf文件和Dockerfile文件详细 <a class="header-anchor" href="#_2、default-conf文件和dockerfile文件详细" aria-label="Permalink to &quot;2、default.conf文件和Dockerfile文件详细&quot;">​</a></h3><p>default.conf配置</p><div class="language-properties"><button title="Copy Code" class="copy"></button><span class="lang">properties</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">server {</span></span>
<span class="line"><span style="color:#A6ACCD;">    listen       80</span><span style="color:#676E95;font-style:italic;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">    server_name  ip地址</span><span style="color:#676E95;font-style:italic;">; # 修改为docker服务宿主机的ip</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">    location / {</span></span>
<span class="line"><span style="color:#A6ACCD;">        root   /usr/share/nginx/html</span><span style="color:#676E95;font-style:italic;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">        index  index.html index.htm</span><span style="color:#676E95;font-style:italic;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">        try_files $uri $uri/ /</span><span style="color:#F07178;">index.html</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;">404</span><span style="color:#676E95;font-style:italic;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">    }</span></span>
<span class="line"><span style="color:#A6ACCD;">     location /api {</span></span>
<span class="line"><span style="color:#A6ACCD;">      proxy_pass http://ip地址:端口号/</span><span style="color:#676E95;font-style:italic;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">    }</span></span>
<span class="line"><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#A6ACCD;">    error_page   500 502 503 504  /50x.html</span><span style="color:#676E95;font-style:italic;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">    </span><span style="color:#F07178;">location</span><span style="color:#A6ACCD;"> </span><span style="color:#89DDFF;">=</span><span style="color:#A6ACCD;"> /50x.html {</span></span>
<span class="line"><span style="color:#A6ACCD;">        root   html</span><span style="color:#676E95;font-style:italic;">;</span></span>
<span class="line"><span style="color:#A6ACCD;">    }</span></span>
<span class="line"><span style="color:#A6ACCD;">}</span></span></code></pre></div><p>Dockerfile配置</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#676E95;font-style:italic;"># 基础镜像使用Nginx</span></span>
<span class="line"><span style="color:#FFCB6B;">FROM</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">nginx</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 作者</span></span>
<span class="line"><span style="color:#FFCB6B;">MAINTAINER</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">renshuo</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 添加时区环境变量，亚洲，上海</span></span>
<span class="line"><span style="color:#FFCB6B;">ENV</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">TimeZone=Asia/Shanghai</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 将前端dist文件中的内容复制到nginx目录</span></span>
<span class="line"><span style="color:#FFCB6B;">COPY</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">dist</span><span style="color:#A6ACCD;">  </span><span style="color:#C3E88D;">/usr/share/nginx/html/</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 用本地的nginx配置文件覆盖镜像的Nginx配置</span></span>
<span class="line"><span style="color:#FFCB6B;">COPY</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">default.conf</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">/etc/nginx/conf.d</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;"># 暴露端口</span></span>
<span class="line"><span style="color:#FFCB6B;">EXPOSE</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">80</span></span></code></pre></div><p>3、上传这三个文件到Linux服务器的同一个文件夹当中，务必放在一起！</p><p><img src="https://mmbiz.qpic.cn/mmbiz_png/eQPyBffYbuezCBTbVJYp5fkWL9HwqdBeyCFmOWVgJcgDIWPqFrmKT7niajEt6XxUEcQIW18IOUrmVNj4RIppJWQ/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p><p>4、构建镜像</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker build -t vue . #点千万别漏了，这里取名镜像为vue，可以随便取名！</span></span></code></pre></div><p>5、查看当前镜像</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">images</span></span></code></pre></div><p>6、创建一个新的容器并运行</p><div class="language-sh"><button title="Copy Code" class="copy"></button><span class="lang">sh</span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#FFCB6B;">docker</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">run</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-d</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">-p</span><span style="color:#A6ACCD;"> </span><span style="color:#F78C6C;">8088</span><span style="color:#C3E88D;">:80</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">--name</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">httvue</span><span style="color:#A6ACCD;"> </span><span style="color:#C3E88D;">vue</span><span style="color:#A6ACCD;"> </span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#将8088端口映射到80端口，端口记得放开</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#httvue为自定义容器名字</span></span>
<span class="line"><span style="color:#676E95;font-style:italic;">#vue是镜像名字</span></span></code></pre></div><p>7、查看正在运行的容器</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki material-theme-palenight"><code><span class="line"><span style="color:#A6ACCD;">docker ps</span></span></code></pre></div><p>8、访问前端页面并测试接口</p><p><img src="https://mmbiz.qpic.cn/mmbiz_png/eQPyBffYbuezCBTbVJYp5fkWL9HwqdBe4gcmYbGnT1c1b3ibAYPmGOnpc5HYficN0hHOiaUibicwaBruV7uev8aIV8g/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" alt="图片"></p></div></div></main><footer class="VPDocFooter" data-v-6b87e69f data-v-37656e44><!--[--><!--]--><!----><nav class="prev-next" data-v-37656e44><div class="pager" data-v-37656e44><a class="pager-link prev" href="/notebook/%E4%B8%89%E9%AB%98/%E9%AB%98%E5%B9%B6%E5%8F%91.html" data-v-37656e44><span class="desc" data-v-37656e44>Previous page</span><span class="title" data-v-37656e44>高并发</span></a></div><div class="pager" data-v-37656e44><a class="pager-link next" href="/notebook/%E4%BA%91%E5%8E%9F%E7%94%9F/K8S.html" data-v-37656e44><span class="desc" data-v-37656e44>Next page</span><span class="title" data-v-37656e44>K8S</span></a></div></nav></footer><!--[--><!--]--></div></div></div><!--[--><!--]--></div></div><!----><!--[--><!--]--></div></div>
    <script>window.__VP_HASH_MAP__=JSON.parse("{\"2、数据库_mysql_mysql面试_基础.md\":\"40da680a\",\"1、学前端_5、小程序_小程序项目.md\":\"60a1629b\",\"1、学前端_4、node_知识篇.md\":\"a7fb500e\",\"1、学前端_2、js_ts_es6 进阶.md\":\"6d07ba10\",\"1、学前端_3、vue_vue3_vue3进阶.md\":\"7ac622b4\",\"5、运维_jenkins.md\":\"929081f8\",\"1、学前端_2、js_ts_typescript.md\":\"875a4aa4\",\"2、数据库_mysql_mysql核心_设计.md\":\"7faf46d1\",\"2、数据库_mysql_mysql核心_基础.md\":\"d8e97f3e\",\"1、学前端_1、html_css_html基础.md\":\"7584d076\",\"1、学前端_5、专题篇_问题篇.md\":\"e893aaa2\",\"2、数据库_mysql_mysql面试_进阶.md\":\"f934806d\",\"3、springboot_运维_原理.md\":\"f4a39db6\",\"2、数据库_influxdb.md\":\"6e1711e1\",\"3、springboot_新特性.md\":\"cdf3e307\",\"mybatis_mybatisplus_jpa.md\":\"8e41681b\",\"1、学前端_5、小程序_小程序优化.md\":\"a2185198\",\"2、数据库_redis_redis基础.md\":\"856df0e0\",\"linux_实用脚本.md\":\"f2299dd5\",\"4、微服务_必备_分布式基础.md\":\"d49863d5\",\"2、数据库_redis_redis优化.md\":\"e66ae32f\",\"4、微服务_springsecurity_进阶篇.md\":\"235a8e9e\",\"5、运维_chatgpt.md\":\"10db3823\",\"2、数据库_mysql_分库分表.md\":\"e1c8a095\",\"start.md\":\"9bc1ff8d\",\"5、运维_github.md\":\"2ec6c735\",\"java学前端_css.md\":\"f11b47f0\",\"1、学前端_5、专题篇_知识篇.md\":\"a463ed8d\",\"linux_软件部署.md\":\"d6722925\",\"2、数据库_neo4j.md\":\"97ad22ac\",\"team.md\":\"ce467a6a\",\"nginx_实战篇.md\":\"7785486e\",\"index.md\":\"8c3ec167\",\"计算机基础_计算机网络_网络基础.md\":\"7a54a85d\",\"1、学前端_4、node_进阶篇.md\":\"60f6db69\",\"java_java集合.md\":\"a049b313\",\"1、学前端_3、vue_vue3_vue3高级.md\":\"614d1516\",\"1、学前端_5、小程序_微信小程序.md\":\"9a4be771\",\"5、运维_netty.md\":\"12ca0278\",\"2、数据库_mysql_mysql核心_运维.md\":\"83f97c16\",\"idea_vs code.md\":\"afdcb593\",\"java学前端_vue3_组件.md\":\"1086884e\",\"idea_chrome.md\":\"4a32afbc\",\"云原生_k8s.md\":\"db58e65a\",\"2、数据库_mysql_mysql核心_进阶.md\":\"61d16dff\",\"ssm_springbatch.md\":\"f799ab4a\",\"三高_分布式.md\":\"db1b8a1b\",\"2、数据库_elasticsearch_1、es基础.md\":\"04d17448\",\"linux_linux基础.md\":\"4b0bf394\",\"idea_idea插件.md\":\"fa86e45a\",\"可视化 _ 监控_可视化大屏.md\":\"004553bd\",\"2、数据库_mongodb_整合.md\":\"3c47d7f4\",\"4、微服务_springsecurity_基础篇.md\":\"534a3401\",\"4、微服务_进阶.md\":\"69095c58\",\"计算机基础_计算机基础_操作系统.md\":\"0f75d113\",\"可视化 _ 监控_zabbix.md\":\"71f2270e\",\"nginx_基础篇.md\":\"c7d8bb50\",\"1、学前端_4、node_项目实战.md\":\"bc5065b8\",\"2、数据库_redis_redis原理.md\":\"5cedf685\",\"可视化 _ 监控_监控基础.md\":\"ac56ce4d\",\"三高_高并发.md\":\"ea9ffc99\",\"2、数据库_redis_redis高级.md\":\"1d5872f6\",\"1、学前端_4、node_基础篇.md\":\"581cc13a\",\"2、数据库_mongodb_基础.md\":\"fb7a0a29\",\"idea_idea基础.md\":\"6f2f9638\",\"4、微服务_必备_sentinel.md\":\"2edfbf6c\",\"2、数据库_elasticsearch_3、es高级.md\":\"ef146606\",\"1、学前端_3、vue_vue3_vue3新语法.md\":\"8afd5409\",\"消息中间件_canal.md\":\"3949163c\",\"ssm_maven.md\":\"2c5e12ed\",\"4、微服务_springsecurity_高级篇.md\":\"882d3ff3\",\"linux_linux进阶.md\":\"188ef7b4\",\"计算机基础_设计模式_uml.md\":\"634ba256\",\"计算机基础_算法_leetcode.md\":\"77162fb9\",\"项目实战_小兔鲜_进阶篇1.md\":\"17c52c81\",\"1、学前端_2、js_ts_es6 基础.md\":\"fda3f18b\",\"项目实战_小兔鲜_进阶篇2.md\":\"a0f23006\",\"软件测试_测试基础.md\":\"8c1060cd\",\"2、数据库_redis_本地缓存.md\":\"00617fe6\",\"nginx_面试篇.md\":\"e3fb373a\",\"mybatis_mybatisplus_mybatis.md\":\"9239e0ad\",\"linux_shell.md\":\"ae53d83b\",\"2、数据库_mysql_mysql核心_优化.md\":\"36230425\",\"项目实战_项目推荐.md\":\"f9d97630\",\"mybatis_mybatisplus_mybatisplus.md\":\"0030fd35\",\"项目实战_百度地图_进阶篇.md\":\"c8b93267\",\"三高_高可用.md\":\"323840c5\",\"java_java新特性.md\":\"22abf56d\",\"软件测试_压力测试.md\":\"9ab44440\",\"java学前端_html_js.md\":\"e0fcd240\",\"2、数据库_redis_redis实战.md\":\"d6daeeab\",\"nginx_进阶篇.md\":\"e6b63195\",\"三高_秒杀.md\":\"3878bb64\",\"5、运维_git.md\":\"0264925c\",\"java_java进阶.md\":\"e79cb5b4\",\"并发 _ 多线程_基础篇.md\":\"7adbfac5\",\"项目实战_百度地图_基础篇.md\":\"8afa5954\",\"java学前端_react.md\":\"3ec827dd\",\"1、学前端_1、html_css_css基础.md\":\"01b56712\",\"项目实战_小兔鲜_基础篇.md\":\"646f5df5\",\"1、学前端_2、js_ts_js 基础.md\":\"cb13e36f\",\"可视化 _ 监控_监控进阶.md\":\"0cdbc292\",\"计算机基础_设计模式_基础篇.md\":\"51617287\",\"计算机基础_数据结构_基础篇.md\":\"b2bfd8d4\",\"项目实战_苍穹外卖_进阶篇.md\":\"48415e41\",\"ssm_spring.md\":\"ab514659\",\"消息中间件_rabbitmq.md\":\"45b1eb28\",\"1、学前端_1、html_css_网页进阶.md\":\"db998248\",\"消息中间件_kafka.md\":\"b747dabf\",\"云原生_docker.md\":\"983c7ba7\",\"4、微服务_必备_分布式锁.md\":\"5af1cf8d\",\"消息中间件_rocketmq.md\":\"d441da85\",\"项目实战_黑马头条_基础篇.md\":\"b05af3a6\",\"ssm_springmvc.md\":\"81b9714f\",\"项目实战_支付.md\":\"1d7407dd\",\"项目实战_黑马头条_进阶篇2.md\":\"bff0015b\",\"项目实战_黑马头条_进阶篇.md\":\"19f18388\",\"java学前端_vue2_组件.md\":\"58c6b1df\",\"3、springboot_基础篇.md\":\"529c66f4\",\"3、springboot_应用篇.md\":\"8b92aa61\",\"项目实战_黑马头条_高级篇.md\":\"227c08c1\",\"1、学前端_5、小程序_uniapp.md\":\"71a282b4\",\"项目实战_云尚办公_基础篇.md\":\"1fe188ba\",\"并发 _ 多线程_并发完善.md\":\"26619c46\",\"1、学前端_2、js_ts_js 进阶.md\":\"657dfb8f\",\"java_java高级.md\":\"23782d1a\",\"java_java基础.md\":\"86d67c77\"}");window.__VP_SITE_DATA__=JSON.parse("{\"lang\":\"en-US\",\"dir\":\"ltr\",\"title\":\"VitePress\",\"description\":\"A VitePress site\",\"base\":\"/notebook/\",\"head\":[],\"appearance\":true,\"themeConfig\":{\"algolia\":{\"appId\":\"DW7O63I9IR\",\"apiKey\":\"f8ed758cdb288a8b06542bc35923c1a1\",\"indexName\":\"notebook\"},\"sidebar\":[{\"text\":\"Java\",\"collapsed\":true,\"items\":[{\"text\":\"Java基础\",\"link\":\"/Java/Java基础\"},{\"text\":\"Java新特性\",\"link\":\"/Java/Java新特性\"},{\"text\":\"Java进阶\",\"link\":\"/Java/Java进阶\"},{\"text\":\"Java集合\",\"link\":\"/Java/Java集合\"},{\"text\":\"Java高级\",\"link\":\"/Java/Java高级\"}]},{\"text\":\"Linux\",\"collapsed\":true,\"items\":[{\"text\":\"Linux基础\",\"link\":\"/Linux/Linux基础\"},{\"text\":\"Linux新特性\",\"link\":\"/Linux/Linux进阶\"},{\"text\":\"Shell脚本\",\"link\":\"/Linux/Shell\"},{\"text\":\"实用脚本\",\"link\":\"/Linux/实用脚本\"},{\"text\":\"软件部署\",\"link\":\"/Linux/软件部署\"}]},{\"text\":\"Nginx\",\"collapsed\":true,\"items\":[{\"text\":\"基础篇\",\"link\":\"/Nginx/基础篇\"},{\"text\":\"进阶篇\",\"link\":\"/Nginx/进阶篇\"},{\"text\":\"实战篇\",\"link\":\"/Nginx/实战篇\"},{\"text\":\"面试篇\",\"link\":\"/Nginx/面试篇\"}]},{\"text\":\"SSM\",\"collapsed\":true,\"items\":[{\"text\":\"Maven\",\"link\":\"/SSM/Maven\"},{\"text\":\"Spring\",\"link\":\"/SSM/Spring\"},{\"text\":\"SpringMVC\",\"link\":\"/SSM/SpringMVC\"},{\"text\":\"SpringBatch\",\"link\":\"/SSM/SpringBatch\"}]},{\"text\":\"SpringBoot\",\"collapsed\":true,\"items\":[{\"text\":\"基础篇\",\"link\":\"/3、SpringBoot/基础篇\"},{\"text\":\"应用篇\",\"link\":\"/3、SpringBoot/应用篇\"},{\"text\":\"新特性\",\"link\":\"/3、SpringBoot/新特性\"},{\"text\":\"运维&原理\",\"link\":\"/3、SpringBoot/运维&原理\"}]},{\"text\":\"SpringCloud\",\"collapsed\":true,\"items\":[{\"text\":\"SpringCloud\",\"link\":\"/4、微服务/进阶\"},{\"text\":\"Sentinel\",\"link\":\"/4、微服务/必备/Sentinel\"}]},{\"text\":\"SpringSecurity\",\"collapsed\":true,\"items\":[{\"text\":\"SpringSecurity基础篇\",\"link\":\"/4、微服务/SpringSecurity/基础篇\"},{\"text\":\"SpringSecurity进阶篇\",\"link\":\"/4、微服务/SpringSecurity/进阶篇\"},{\"text\":\"SpringSecurity高级篇\",\"link\":\"/4、微服务/SpringSecurity/高级篇\"}]},{\"text\":\"Mybatis & MybatisPlus\",\"collapsed\":true,\"items\":[{\"text\":\"Mybatis\",\"link\":\"/Mybatis&MybatisPlus/Mybatis\"},{\"text\":\"MybatisPlus\",\"link\":\"/Mybatis&MybatisPlus/MybatisPlus\"},{\"text\":\"JPA\",\"link\":\"/Mybatis&MybatisPlus/JPA\"}]},{\"text\":\"Git & ChatGPT\",\"collapsed\":true,\"items\":[{\"text\":\"Git\",\"link\":\"/5、运维/Git\"},{\"text\":\"Github\",\"link\":\"/5、运维/Github\"},{\"text\":\"ChatGPT\",\"link\":\"/5、运维/ChatGPT\"},{\"text\":\"Jenkins\",\"link\":\"/5、运维/Jenkins\"},{\"text\":\"Netty\",\"link\":\"/5、运维/Netty\"}]},{\"text\":\"数据库\",\"collapsed\":true,\"items\":[{\"text\":\"MySQL\",\"collapsed\":true,\"items\":[{\"text\":\"MySQL基础\",\"link\":\"/2、数据库/MySQL/MySQL核心/基础\"},{\"text\":\"MySQL进阶\",\"link\":\"/2、数据库/MySQL/MySQL核心/进阶\"},{\"text\":\"MySQL优化\",\"link\":\"/2、数据库/MySQL/MySQL核心/优化\"},{\"text\":\"MySQL设计\",\"link\":\"/2、数据库/MySQL/MySQL核心/设计\"},{\"text\":\"MySQL运维\",\"link\":\"/2、数据库/MySQL/MySQL核心/运维\"},{\"text\":\"分库分表\",\"link\":\"/2、数据库/MySQL/分库分表\"}]},{\"text\":\"Redis\",\"collapsed\":true,\"items\":[{\"text\":\"Redis基础\",\"link\":\"/2、数据库/Redis/Redis基础\"},{\"text\":\"Redis优化\",\"link\":\"/2、数据库/Redis/Redis优化\"},{\"text\":\"Redis原理\",\"link\":\"/2、数据库/Redis/Redis原理\"},{\"text\":\"Redis高级\",\"link\":\"/2、数据库/Redis/Redis高级\"},{\"text\":\"Redis实战\",\"link\":\"/2、数据库/Redis/Redis实战\"},{\"text\":\"本地缓存\",\"link\":\"/2、数据库/Redis/本地缓存\"}]},{\"text\":\"MongoDB\",\"collapsed\":true,\"items\":[{\"text\":\"MongoDB基础\",\"link\":\"/2、数据库/MongoDB/基础\"},{\"text\":\"MongoDB进阶\",\"link\":\"/2、数据库/MongoDB/整合\"}]},{\"text\":\"ElasticSearch\",\"collapsed\":true,\"items\":[{\"text\":\"ES基础\",\"link\":\"/2、数据库/ElasticSearch/1、ES基础\"},{\"text\":\"ES高级\",\"link\":\"/2、数据库/ElasticSearch/3、ES高级\"}]},{\"text\":\"InfluxDB\",\"link\":\"/2、数据库/influxdb\"},{\"text\":\"Neo4j\",\"link\":\"/2、数据库/Neo4j\"}]},{\"text\":\"高并发 & 秒杀 & 分布式\",\"collapsed\":true,\"items\":[{\"text\":\"分布式理论\",\"link\":\"/三高/分布式\"},{\"text\":\"分布式锁\",\"link\":\"/4、微服务/必备/分布式锁\"},{\"text\":\"秒杀\",\"link\":\"/三高/秒杀\"},{\"text\":\"高可用\",\"link\":\"/三高/高可用\"},{\"text\":\"高并发\",\"link\":\"/三高/高并发\"}]},{\"text\":\"云原生\",\"collapsed\":true,\"items\":[{\"text\":\"Docker\",\"link\":\"/云原生/Docker\"},{\"text\":\"K8S\",\"link\":\"/云原生/K8S\"}]},{\"text\":\"可视化 & 监控\",\"collapsed\":true,\"items\":[{\"text\":\"监控基础\",\"link\":\"/可视化 & 监控/监控基础\"},{\"text\":\"监控进阶\",\"link\":\"/可视化 & 监控/监控进阶\"},{\"text\":\"可视化大屏\",\"link\":\"/可视化 & 监控/可视化大屏\"},{\"text\":\"Zabbix\",\"link\":\"/可视化 & 监控/Zabbix\"}]},{\"text\":\"学前端\",\"collapsed\":true,\"items\":[{\"text\":\"HTML+CSS\",\"collapsed\":true,\"items\":[{\"text\":\"HTML基础\",\"link\":\"/1、学前端/1、HTML+CSS/HTML基础\"},{\"text\":\"CSS基础\",\"link\":\"/1、学前端/1、HTML+CSS/CSS基础\"},{\"text\":\"网页进阶\",\"link\":\"/1、学前端/1、HTML+CSS/网页进阶\"}]},{\"text\":\"JS+TS\",\"collapsed\":true,\"items\":[{\"text\":\"JS基础\",\"link\":\"/1、学前端/2、JS+TS/JS 基础\"},{\"text\":\"JS进阶\",\"link\":\"/1、学前端/2、JS+TS/JS 进阶\"},{\"text\":\"ES6基础\",\"link\":\"/1、学前端/2、JS+TS/ES6 基础\"},{\"text\":\"ES6进阶\",\"link\":\"/1、学前端/2、JS+TS/ES6 进阶\"},{\"text\":\"TS基础\",\"link\":\"/1、学前端/2、JS+TS/TypeScript\"}]},{\"text\":\"NodeJS\",\"collapsed\":true,\"items\":[{\"text\":\"Node基础\",\"link\":\"/1、学前端/4、Node/基础篇\"},{\"text\":\"Node进阶\",\"link\":\"/1、学前端/4、Node/进阶篇\"},{\"text\":\"项目实战\",\"link\":\"/1、学前端/4、Node/项目实战\"}]},{\"text\":\"Vue\",\"collapsed\":true,\"items\":[{\"text\":\"Vue3进阶\",\"link\":\"/1、学前端/3、Vue/Vue3/Vue3进阶\"},{\"text\":\"Vue3高级\",\"link\":\"/1、学前端/3、Vue/Vue3/Vue3高级\"},{\"text\":\"Vue3新语法\",\"link\":\"/1、学前端/3、Vue/Vue3/Vue3新语法\"},{\"text\":\"项目实战\",\"link\":\"/1、学前端/3、Vue/Vue2/Vue2项目\"}]},{\"text\":\"小程序\",\"collapsed\":true,\"items\":[{\"text\":\"小程序基础\",\"link\":\"/1、学前端/5、小程序/微信小程序\"},{\"text\":\"小程序优化\",\"link\":\"/1、学前端/5、小程序/小程序优化\"},{\"text\":\"uniapp\",\"link\":\"/1、学前端/5、小程序/uniapp\"},{\"text\":\"项目实战\",\"link\":\"/1、学前端/5、小程序/小程序项目\"}]}]},{\"text\":\"计算机基础\",\"collapsed\":true,\"items\":[{\"text\":\"数据结构\",\"link\":\"/计算机基础/数据结构/基础篇\"},{\"text\":\"操作系统\",\"link\":\"/计算机基础/计算机基础/操作系统\"},{\"text\":\"设计模式\",\"link\":\"/计算机基础/设计模式/基础篇\"},{\"text\":\"计算机网络\",\"link\":\"/计算机基础/计算机网络/网络基础\"},{\"text\":\"UML\",\"link\":\"/计算机基础/设计模式/UML\"},{\"text\":\"LeetCode\",\"link\":\"/计算机基础/算法/LeetCode\"}]},{\"text\":\"项目实战\",\"collapsed\":true,\"items\":[{\"text\":\"云尚办公\",\"collapsed\":true,\"items\":[{\"text\":\"基础篇\",\"link\":\"/项目实战/云尚办公/基础篇\"}]},{\"text\":\"小兔鲜\",\"collapsed\":true,\"items\":[{\"text\":\"基础篇\",\"link\":\"/项目实战/小兔鲜/基础篇\"},{\"text\":\"进阶篇1\",\"link\":\"/项目实战/小兔鲜/进阶篇1\"},{\"text\":\"进阶篇2\",\"link\":\"/项目实战/小兔鲜/进阶篇2\"}]},{\"text\":\"地图\",\"collapsed\":true,\"items\":[{\"text\":\"基础篇\",\"link\":\"/项目实战/百度地图/基础篇\"},{\"text\":\"进阶篇\",\"link\":\"/项目实战/百度地图/进阶篇\"}]},{\"text\":\"苍穹外卖\",\"collapsed\":true,\"items\":[{\"text\":\"进阶篇\",\"link\":\"/项目实战/苍穹外卖/进阶篇\"}]},{\"text\":\"黑马头条\",\"collapsed\":true,\"items\":[{\"text\":\"基础篇\",\"link\":\"/项目实战/黑马头条/基础篇\"},{\"text\":\"进阶篇\",\"link\":\"/项目实战/黑马头条/进阶篇\"},{\"text\":\"进阶篇2\",\"link\":\"/项目实战/黑马头条/进阶篇2\"},{\"text\":\"高级篇\",\"link\":\"/项目实战/黑马头条/高级篇\"}]},{\"text\":\"支付\",\"link\":\"/项目实战/支付\"},{\"text\":\"项目推荐\",\"link\":\"/项目实战/项目推荐\"}]},{\"text\":\"团队成员\",\"link\":\"/team\"}],\"siteTitle\":\"任硕的文档\",\"logo\":\"/Vue.png\",\"nav\":[{\"text\":\"Java学前端\",\"items\":[{\"items\":[{\"text\":\"HTML+JS\",\"link\":\"/Java学前端/HTML+JS\"},{\"text\":\"CSS\",\"link\":\"/Java学前端/CSS\"},{\"text\":\"Vue2+组件\",\"link\":\"/Java学前端/Vue2+组件\"},{\"text\":\"Vue3+组件\",\"link\":\"/Java学前端/Vue3+组件\"},{\"text\":\"React\",\"link\":\"/Java学前端/React\"}]}],\"activeMatch\":\"/Java/\"},{\"text\":\"软件测试\",\"items\":[{\"items\":[{\"text\":\"测试基础\",\"link\":\"/软件测试/测试基础\"},{\"text\":\"压力测试\",\"link\":\"/软件测试/压力测试\"}]}]},{\"text\":\"多线程\",\"items\":[{\"items\":[{\"text\":\"基础篇\",\"link\":\"/并发 & 多线程/基础篇\"},{\"text\":\"进阶篇\",\"link\":\"/并发 & 多线程/并发完善\"}]}]},{\"text\":\"开发工具\",\"items\":[{\"items\":[{\"text\":\"Chrome\",\"link\":\"/IDEA/Chrome\"},{\"text\":\"IDEA基础\",\"link\":\"/IDEA/IDEA基础\"},{\"text\":\"IDEA插件\",\"link\":\"/IDEA/IDEA插件\"},{\"text\":\"VS Code\",\"link\":\"/IDEA/VS Code\"}]}]},{\"text\":\"消息中间件\",\"items\":[{\"items\":[{\"text\":\"RabbitMQ\",\"link\":\"/消息中间件/RabbitMQ\"},{\"text\":\"RocketMQ\",\"link\":\"/消息中间件/RocketMQ\"},{\"text\":\"Kafka\",\"link\":\"/消息中间件/Kafka\"},{\"text\":\"Canal\",\"link\":\"/消息中间件/Canal\"}]}]}],\"socialLinks\":[{\"icon\":\"github\",\"link\":\"https://github.com/renshuo123/renshuo123.github.io\"},{\"icon\":\"twitter\",\"link\":\"#\"},{\"icon\":{\"svg\":\"<svg t=\\\"1676028692954\\\" class=\\\"icon\\\" ...</path></svg>\"},\"link\":\"https://github.com/\"}]},\"locales\":{},\"scrollOffset\":90,\"cleanUrls\":false}");</script>
    
  </body>
</html>